Validity metrics
Use validity metrics in SodaCL checks to detect invalid values in a dataset.
Use a validity metric in a check to surface invalid or unexpected values in your dataset.
checks for dim_customer:
# Check for valid values
- invalid_count(email_address) = 0:
valid format: email
- invalid_percent(english_education) = 0:
valid length: 100
- invalid_percent(total_children) <= 2:
valid max: 6
- invalid_percent(marital_status) = 0:
valid max length: 10
- invalid_count(number_cars_owned) = 0:
valid min: 1
- invalid_percent(marital_status) = 0:
valid min length: 1
- invalid_percent(last_name) < 5%:
invalid regex: (?:XX)
- invalid_count(house_owner_flag) = 0:
valid values: [0, 1]
checks for dim_customer:
# Check for invalid values
- invalid_count(first_name) = 0:
invalid values: [Antonio]
- invalid_count(number_cars_owned) = 0:
invalid values: [0, 3]
✖️ Requires Soda Core Scientific (included in a Soda Agent) ✔️ Supported in Soda Core ✔️ Supported in Soda Library + Soda Cloud ✔️ Supported in Soda Cloud Agreements + Soda Agent ✔️ Available as a no-code check with a self-hosted Soda Agent connected to any Soda-supported data source, except Spark, and Dask and Pandas OR with a Soda-hosted Agent connected to a BigQuery, Databricks SQL, MS SQL Server, MySQL, PostgreSQL, Redshift, or Snowflake data source
Define checks with validity metrics
In the context of SodaCL check types, you use validity metrics in standard checks. Refer to Standard check types for exhaustive configuration details.
You can use all validity metrics in checks that apply to individual columns in a dataset; you cannot use validity metrics in checks that apply to entire datasets. Identify the column by adding a value in the argument between brackets in the check.
You must use a configuration key:value pair to define what qualifies as an valid value or invalid value.
If you wish, you can add a
%
character to the threshold for ainvalid_percent
metric for improved readability. This character does not behave as a wildard in this context.
checks for dim_customer
- invalid_count(number_cars_owned) = 0:
valid min: 1
You can use validity metrics in checks with fixed thresholds, or relative thresholds, but not change-over-time thresholds. See Checks with fixed thresholds for more detail.
checks for dim_reseller:
# a check with a fixed threshold
- invalid_count(email_address) = 0:
valid format: email
# a check with a relative threshold
- invalid_percent(english_education) < 3%:
valid max length: 100
Specify valid or invalid values
Use a nested configuration key:value pair to provide your own definition of a valid or invalid value. There are several configuration keys that you can use to define what qualifies as valid; the examples below illustrate the use of just a few config keys. See a complete List of configuration keys below.
A check that uses a validity metric has six mutable parts:
a metric
an argument
a comparison symbol or phrase
a threshold
a configuration key
a configuration value
The example below defines two checks. The first check applies to the column house_owner_flag
. The valid values
configuration key specifies that if a row in that column contains anything other than the two valid values in the list, Soda registers them as invalid. The check fails if Soda discovers any values that are not 0
or 1
.
Values in a list must be enclosed in square brackets.
Known issue: Do not wrap numeric values in single quotes if you are scanning data in a BigQuery data source.
The second check uses a regular expression to define what qualifies as an invalid value in the last_name
column so that any values that match the pattern defined by the regex qualify as invalid.
checks for dim_customer:
- invalid_count(house_owner_flag) = 0:
valid values: [0, 1]
- invalid_count(last_name) = 0:
invalid regex: (?:XX)
First check:
metric
invalid_count
argument
house_owner_flag
comparison symbol
=
threshold
0
configuration key
valid values
configuration value(s)
0, 1
Second check:
metric
invalid_count
argument
last_name
comparison symbol or phrase
=
threshold
0
configuration key
invalid regex
configuration value(s)
(?:XX)
The invalid values
configuration key specifies that if a row in that column contains the invalid values in the list, Soda registers them as invalid. In the example below, the check fails if Soda discovers any values that are Antonio
.
Values in a list must be enclosed in square brackets.
checks for dim_customer:
- invalid_count(first_name) = 0:
invalid values: [Antonio]
Specify valid format
If the data type of the column you are checking is TEXT (such as character, character varying, or string) then you can use the valid format
configuration key. This config key uses built-in values that test the data in the column for specific formats, such as email address format, date format, or uuid format. See List of valid formats below.
The check below validates that all values in the email_address
column conform to an email address format.
checks for dim_customer:
- invalid_percent(email_address) = 0:
valid format: email
metric
invalid_percent
argument
email_address
comparison symbol or phrase
=
threshold
0
configuration key
valid format
configuration value(s)
email
Troubleshoot valid format and values
Problem: You are using a valid format
to test the format of values in a column and the CLI returns the following error message when you run a scan.
| HINT: No operator matches the given name and argument types. You might need to add explicit type casts.
Error occurred while executing scan.
| unsupported operand type(s) for *: 'Undefined' and 'int'
Solution: The error indicates that the data type of the column is not TEXT. Adjust your check to use a different configuration key, instead.
Failed row samples
Checks with validity metrics automatically collect samples of any failed rows to display Soda Cloud. The default number of failed row samples that Soda collects and displays is 100.
If you wish to limit or broaden the sample size, you can use the samples limit
configuration in a check with a validity metric. You can add this configuration to your checks YAML file for Soda Library, or when writing checks as part of an agreement in Soda Cloud. See: Set a sample limit.
checks for dim_customer:
- invalid_percent(email_address) < 50:
samples limit: 2
For security, you can add a configuration to your data source connection details to prevent Soda from collecting failed rows samples from specific columns that contain sensitive data. See: Disable failed row samples.
Alternatively, you can set the samples limit
to 0
to prevent Soda from collecting and sending failed rows samples for an individual check, as in the following example.
checks for dim_customer:
- invalid_percent(email_address) < 50:
samples limit: 0
You can also use a samples columns
or a collect failed rows
configuration to a check to specify the columns for which Soda must implicitly collect failed row sample values, as in the following example with the former. Soda only collects this check’s failed row samples for the columns you specify in the list. See: Customize sampling for checks.
Note that the comma-separated list of samples columns does not support wildcard characters (%).
checks for dim_employee:
- invalid_count(gender) = 0:
valid values: ["M", "Q"]
samples columns: [employee_key, first_name]
To review the failed rows in Soda Cloud, navigate to the Checks dashboard, then click the row for a check for validity values. Examine failed rows in the Failed Rows Analysis tab; see Manage failed row samples for further details.

Optional check configurations
✓
Define alert configurations to specify warn and fail thresholds; see example.
✓
Apply an in-check filter to return results for a specific portion of the data in your dataset; see example.
✓
Use quotes when identifying dataset or column names; see example. Note that the type of quotes you use must match that which your data source uses. For example, BigQuery uses a backtick (`) as a quotation mark.
Use wildcard characters ( % or * ) in values in the check.
-
✓
Use for each to apply checks with validity metrics to multiple datasets in one scan; see example.
✓
Supports samples columns
parameter to specify columns from which Soda draws failed row samples.
✓
Supports samples limit
parameter to control the volume of failed row samples Soda collects.
✓
Supports collect failed rows
parameter instruct Soda to collect, or not to collect, failed row samples for a check.
Example with check name
checks for dim_customer:
- invalid_count(first_name) = 0 :
valid min length: 2
name: First name has 2 or more characters
Example with alert configuration
- invalid_count(house_owner_flag):
valid values: [0, 1]
warn: when between 1 and 5
fail: when > 6
Example with in-check filter
checks for dim_customer:
- invalid_percent(marital_status) = 0:
valid max length: 1
filter: total_children = 0
Example with quotes
checks for dim_customer:
- invalid_count("number_cars_owned") = 0:
valid min: 1
Example with for each
for each dataset T:
datasets:
- dim_customer
- dim_customer_%
checks:
- invalid_count(email_address) = 0:
valid format: email
Example with dataset filter
filter CUSTOMERS [daily]:
where: TIMESTAMP '{ts_start}' <= "ts" AND "ts" < TIMESTAMP '${ts_end}'
checks for CUSTOMERS [daily]:
- invalid_count(email_address) = 0:
valid format: email
List of validity metrics
invalid_count
invalid format
invalid values
valid format
valid length
valid max
valid max length
valid min
valid min length
valid values
The number of rows in a column that contain values that are not valid.
number text time
invalid regex
valid regex
text
invalid_percent
invalid format
invalid values
valid format
valid length
valid max
valid max length
valid min
valid min length
valid values
The percentage of rows in a column, relative to the total row count, that contain values that are not valid.
number text time
invalid regex
valid regex
text
List of configuration keys
The column configuration key:value pair defines what SodaCL ought to consider as valid values.
invalid format
Defines the format of a value that Soda ought to register as invalid. Only works with columns that contain data type TEXT.
invalid regex
Specifies a regular expression to define your own custom invalid values.
regex, no forward slash delimiters
invalid values
Specifies the values that Soda ought to consider invalid.
valid format
Defines the format of a value that Soda ought to register as valid. Only works with columns that contain data type TEXT.
valid length
Specifies a valid length for a string. Works with columns that contain data type TEXT, and also with INTEGER on most databases, where implicit casting from string to integer is supported. Note: PostgreSQL does not support this behavior, as it does not implicitly cast strings to integers for this use case.
integer
valid max
Specifies a maximum numerical value for valid values.
integer or float
valid max length
Specifies a valid maximum length for a string. Only works with columns that contain data type TEXT.
integer
valid min
Specifies a minimum numerical value for valid values.
integer or float
valid min length
Specifies a valid minimum length for a string. Only works with columns that contain data type TEXT.
integer
valid regex
Specifies a regular expression to define your own custom valid values.
regex, no forward slash delimiters
valid values
Specifies the values that Soda ought to consider valid.
values in a list
List of valid formats
Though table below lists valid formats, the same apply for invalid formats.
Valid formats apply only to columns using data type TEXT, not DATE or NUMBER.
The Soda Library package for MS SQL Server has limited support for valid formats. See the separate list below of formats supported for MS SQL Server.
credit card number
Four four-digit numbers separated by spaces. Four four-digit numbers separated by dashes. Sixteen-digit number. Four five-digit numbers separated by spaces.
date eu
Validates date only, not time. dd/mm/yyyy
date inverse
Validates date only, not time. yyyy/mm/dd
date iso 8601
Validates date and/or time according to ISO 8601 format . 2021-04-28T09:00:00+02:00
date us
Validates date only, not time. mm/dd/yyyy
decimal
Number uses a ,
or .
as a decimal indicator.
decimal comma
Number uses ,
as decimal indicator.
decimal point
Number uses .
as decimal indicator.
email
integer
Number is whole.
ip address
Four whole numbers separated by .
ipv4 address
Four whole numbers separated by .
ipv6 address
Eight values separated by :
money
A money pattern with currency symbol + decimal point or comma + currency abbreviation.
money comma
A money pattern with currency symbol + decimal comma + currency abbreviation.
money point
A money pattern with currency symbol + decimal point + currency abbreviation.
negative decimal
Negative number uses a ,
or .
as a decimal indicator.
negative decimal comma
Negative number uses ,
as decimal indicator.
negative decimal point
Negative number uses .
as decimal indicator.
negative integer
Number is negative and whole.
negative percentage
Negative number is a percentage.
negative percentage comma
Negative number is a percentage with a ,
decimal indicator.
negative percentage point
Negative number is a percentage with a .
decimal indicator.
percentage comma
Number is a percentage with a ,
decimal indicator.
percentage point
Number is a percentage with a .
decimal indicator.
percentage
Number is a percentage.
phone number
+12 123 123 1234 123 123 1234 +1 123-123-1234 +12 123-123-1234 +12 123 123-1234 555-2368 555-ABCD
positive decimal
Postive number uses a ,
or .
as a decimal indicator.
positive decimal comma
Positive number uses ,
as decimal indicator.
positive decimal point
Positive number uses .
as decimal indicator.
positive integer
Number is positive and whole.
positive percentage
Positive number is a percentage.
positive percentage comma
Positive number is a percentage with a ,
decimal indicator.
positive percentage point
Positive number is a percentage with a .
decimal indicator.
time 12h
Validates against the 12-hour clock. hh:mm:ss
time 12h nosec
Validates against the 12-hour clock. hh:mm
time 24h
Validates against the 244-hour clock. hh:mm:ss
time 24h nosec
Validates against the 24-hour clock. hh:mm
timestamp 12h
Validates against the 12-hour clock. hh:mm:ss
timestamp 24h
Validates against the 24-hour clock. hh:mm:ss
uuid
Universally unique identifier.
Formats supported with Soda for MS SQL Server
date eu
Validates date only, not time. dd/mm/yyyy
date inverse
Validates date only, not time. yyyy/mm/dd
date us
Validates date only, not time. mm/dd/yyyy
decimal
Number uses a ,
or .
as a decimal indicator.
integer
Number is whole.
ip address
Four whole numbers separated by .
negative integer
Number is negative and whole.
phone number
+12 123 123 1234 123 123 1234 +1 123-123-1234 +12 123-123-1234 +12 123 123-1234 555-2368 555-ABCD
positive integer
Number is positive and whole.
uuid
Universally unique identifier.
List of comparison symbols and phrases
=
<
>
<=
>=
!=
<>
between
not between
Go further
Use validity metrics in checks with alert configurations to establish warn and fail zones
Use validity metrics in checks to define ranges of acceptable thresholds using boundary thresholds.
Reference tips and best practices for SodaCL.
Need help? Join the Soda community on Slack.
Last updated
Was this helpful?