Locoia
Search…
Validation Helper
The validation helper is used to validate CSV files, spreadsheets (e.g., XLSX files), lists, and dictionaries.
The data to be validated is specified in the Data Reference field, which expects a reference just by the ID of the flow step, e.g., spr1.
The user can then choose what action should be taken if a field of a row does not adhere to specified conditions. The possible actions are:
    Terminate flow - will directly terminate the entire flow if a field could not pass the specified validation.
    Drop invalid rows - will drop all rows in which a field could not pass the specified validation and return the remaining rows inside a dictionary called data, while errors are returned inside a dictionary called errors.
    Return errors - will return all the input data inside a dictionary called data, while errors are returned inside a dictionary called errors.
Next, the columns or fields to which the validation should be applied have to be specified; to do so, either write the columns name (if the data comes from a spreadsheet or dictionary) or the column's index (if the data comes from a CSV or list of lists) into the Column field. Afterwards, select the field type for this column or field and a corresponding condition. Finally, you enter the condition value.
Furthermore, one can declare if blank fields should be ignored for the validation or not. This can be repeated for each field or column, which should be validated by adding a new set of fields by clicking the + button.
Example Validation Condition

Examples

Data comes from a CSV file and is hence handled as a list of lists in the flow data handling logic:
1
[
2
[
3
123,
4
"Michael",
5
"United States"
6
],
7
[
8
124,
9
"Maria",
10
"Spain"
11
]
12
]
Copied!
The references to the columns are made by specifying the column index, i.e., 0 for the first column and 2 for the third column (note: the indexes start at 0).
Validation Helper - CSV
The resulting output by the validation helper is:
1
{
2
"data": [
3
{
4
"0": 124,
5
"1": "Maria",
6
"2": "Spain"
7
}
8
],
9
"errors": [
10
{
11
"row": [
12
123,
13
"Michael",
14
"United States"
15
],
16
"errors": [
17
{
18
"2": {
19
"United States": [
20
"max length is 6"
21
]
22
}
23
}
24
]
25
}
26
]
27
}
Copied!
If the same data is provided in the form of an XLSX file, the data would be stores as a list of dictionaries:
1
[
2
{
3
"id": 123,
4
"name": "Michael",
5
"country": "United States"
6
},
7
{
8
"id": 124,
9
"name": "Maria",
10
"country": "Spain"
11
}
12
]
Copied!
Almost all the settings in the Validation Helper could stay the same, except the Data Reference and Column, which would, in this example, be filed with id and country.
The Validation Helper can also work with more complex, nested dictionaries, such as:
1
{
2
"contacts" : [
3
{
4
"id": 123,
5
"name": "Michael",
6
"address": {
7
"country": "United States",
8
"city": "New York"
9
}
10
},
11
{
12
"id": 124,
13
"name": "Maria",
14
"address": {
15
"country": "Spain",
16
"city": "Madrid"
17
}
18
}
19
],
20
"companies": [
21
{
22
"id": 200,
23
"name": "Tech Company",
24
"website": "www.tech.com",
25
}
26
]
27
}
Copied!
In order to only access and validate the contacts (dictionary), in the above example, the path of the nested dictionary, which should be validated, has to be specified in the Data Reference field, e.g., if the data comes from connector xls1, the reference would be xls1.contacts. In this way, one can even reference to nested fields within the contacts dictionary, such as the field country:
Validation Helper - Nested Dictionary
The resulting output in this case is:JavaScript
1
{
2
"data": [
3
{
4
"id": 124,
5
"name": "Maria",
6
"address": {
7
"country": "Spain",
8
"city": "Madrid"
9
}
10
}
11
],
12
"errors": [
13
{
14
"id": 123,
15
"name": "Michael",
16
"address": {
17
"country": "United States",
18
"city": "New York"
19
},
20
"errors": {
21
"address.country": {
22
"United States": [
23
"max length is 6"
24
]
25
}
26
}
27
}
28
]
29
}
Copied!
Last modified 3mo ago
Copy link
Contents
Examples