Skip to main content

Validation rules

A rule file lists checks per field; undatum validate data.csv --rules rules.yml reports every record that breaks one. undatum validate --list-rules prints the same catalogue as this page.

rules:
- name: country code
field: country
format: country # ISO 3166-1 alpha-2 or alpha-3
- field: amount
type: number
min: 0
- field: day
format: date
formats: ["%d.%m.%Y"]
- field: id
required: true
unique: true
- field: country
references: {file: countries.csv, field: code}
severity: warning

Unknown format, rule type or custom names stop the run before any data is read (exit code 2) and name the closest match. Paths in references are relative to the current directory or to the rule file.

undatum validate --list-rules
undatum validate data.csv --rules rules.yml --json
undatum validate data.csv --rules rules.yml -O jsonl > violations.jsonl

With -O jsonl every line is one violation: {"rule", "field", "severity", "row", "value", "message", "rule_type"}; the summary goes to stderr. --json prints the undatum.validate/1 report.

unique remembers every value of the field; above a million values it moves them to a temporary SQLite file, so memory stays bounded. references loads the reference column the same way. Rule files with unique ignore --threads (every record has to be seen by one process).

Reference​

Formats (format: NAME)​

NameValid valuesParameters
emailAn e-mail address (name@domain)
urlAn absolute URL
dateA calendar date; ISO 8601 (2026-10-08) unless 'formats' is givenformats: strptime patterns, e.g. ['%d.%m.%Y']
datetimeA date and time; ISO 8601 unless 'formats' is givenformats: strptime patterns
phoneA phone number: E.164 (+4930123456); national numbers with 'region'region: ISO country code for national numbers
needs undatum[phone] for all features
countryAn ISO 3166-1 country code (DE, DEU)alpha: '2', '3', 'numeric' or 'any' (default)
currencyAn ISO 4217 currency code (EUR)
languageAn ISO 639-1 language code (en; en-GB with a region)allow_region: accept a region suffix such as en-GB (default true)
ibanAn IBAN with a valid check sum
uuidA UUID (any version)
patternThe whole value matches a regular expressionregex: the regular expression
integerA whole number
numberA number (integer or decimal)
booleantrue/false, yes/no or 1/0
ru.org.innA Russian taxpayer number (INN) with valid check digits
ru.org.ogrnA Russian company registration number (OGRN)

Rule keys​

KeyChecks
requiredtrue: the field must be present and not empty (not_null)
uniquetrue: no value may repeat across the file
min / maxnumeric range (inclusive)
min_length / max_lengthtext length range
enumlist of allowed values
patternregular expression the value must match (prefix match)
references{file, field}: the value must exist in that field of another file
conditioncross-field rule: an expression over 'fields' (type: cross-field)