Skip to content

Rule patterns

A patternPattern A reusable way of validating (required, format, fresh and eleven more). Each rule is a pattern applied to a field with its condition. is a way of validating. The list is closed: fourteen patterns, each with its parameters. What none of them covers is written as an expression and reviewed; if it repeats, it becomes a pattern or a named format of Quality Data.

Every pattern also takes the keys every ruleRule It applies a pattern to a field; the pattern gives it its dimension and a default severity. The rules that count are the ones on main, the approved version. has (when, population, severity, cause, alert, examples…), described in Rule language. A parameter a pattern does not take is a lint error (QR005); one it needs and lacks is another (QR006).

Pattern Fails when DimensionDimension The kind of quality a rule measures (completeness, validity, timeliness…), given by its pattern. Default severitySeverity A rule's weight in the ICD: blocking 1.0, major 0.6 and minor 0.3. The pattern gives a rule its default severity.
required The value is empty or a placeholder CompletenessCompleteness Quality dimension: the data is present when it must be. Blocking
empty The value is filled when it must not be ConsistencyConsistency Quality dimension: the data does not contradict other fields or sources (for example, net worth = assets − liabilities). Major
placeholder The value is a filler AccuracyAccuracy Quality dimension: the value represents reality correctly. Without an external source it is approximated by plausibility. Major
length The length is not allowed ValidityValidity Quality dimension: the data has the right form and an allowed value (an e-mail with an @ and a domain; a region from its list). Major
format The value does not have its form Validity Major
domain The value is not in its list or reference Validity Major
range The value is outside its bounds Accuracy Major
fresh A date is older than its validity TimelinessTimeliness Quality dimension: the data is up to date. A mobile phone that was right five years ago may not be today. Major
sum A total differs from its parts Consistency Major
unique The value repeats across records UniquenessUniqueness Quality dimension: an entity appears only once (a unique document; a mobile phone or e-mail not shared). Minor
combination A combination of fields is not allowed Consistency Major
implies A condition holds and its consequence does not Consistency Major
differs Two fields hold the same value Consistency Minor
expression A free condition holds Its own Major

Empty values. What counts as empty, and why the other patterns leave empty values to required, is in Rule language: what Quality Data decides for every rule. Each section below says which fields a pattern skips on when they are empty, and whether on_empty: fail counts them instead.

The field has a value. Fails when it is empty, or holds one of the datasetDataset One table of a source as Quality Data reads it: a name, its fields and the rules that check them.’s placeholders for its type (the reason then says “placeholder”).

  • Parameters: none.
  • Empty values: they are what it finds. on_empty does not apply.
- id: EMP-01
field: Employer
check: required
when: Occupation = 'EMPLOYEE'
alert: The employer is missing for an employee

Lint warns when a field has both required and placeholder (QR022): required already counts the fillers.

The field has no value where it must not have one. Fails when it is filled.

  • Parameters: none.
  • Empty values: an empty value passes. A placeholder counts as filled. on_empty does not apply.
- id: EMP-02
field: Employer
check: empty
when: Occupation = 'STUDENT'
alert: A student has an employer

The value is not a filler, such as UPDATE or 1900-01-01.

  • Parameters: values, the fillers to find; by default the datasetDataset One table of a source as Quality Data reads it: a name, its fields and the rules that check them.’s placeholders for the field’s type. A * stands for any text (noemail@*).
  • Empty values: skipped; on_empty: fail counts them.
- id: CITY-03
field: City
check: placeholder
values: [UPDATE, NO CITY]
alert: The city holds a filler

The value’s length, without its outer spaces, is allowed.

  • Parameters: in, a list of allowed lengths; min, max, the bounds (both included). At least one of them.
  • Empty values: skipped; on_empty: fail counts them.
- id: MOB-02
field: Mobile
check: length
in: [10]
alert: A mobile number has 10 digits

The value, without its outer spaces, has its form.

  • Parameters: pattern, a regular expression, or named, a format maintained by Quality Data; one of the two, never both. The expression must match the whole value (it is anchored), and is RE2Google's regular-expression engine The dialect the rules' regular expressions are written in; it always runs in predictable time, so it has no backreferences or lookaround., Google’s dialect: no backreferences, no lookaround (QR010).
  • Empty values: skipped; on_empty: fail counts them.
named Accepts
email An e-mail address: a local part, @, and a domain with a dot
person_name Letters (accents included), words joined by one space, ' or -
not_only_symbols At least one letter or digit
capitalized Starts with an upper-case letter
normalized_spaces No doubled spaces between words

Three more named formats, for Colombian data, are in an optional module.

- id: EML-02
field: Email
check: format
named: email
alert: Not an e-mail address
- id: DOC-02
field: Document
check: format
pattern: \d{5,12}
alert: The document has 5 to 12 digits

A regular expression is written plain, as above: YAMLYAML Ain't Markup Language A plain-text format, easy for people to read and write, in which rules are written., the format rulesRule It applies a pattern to a field; the pattern gives it its dimension and a default severity. The rules that count are the ones on main, the approved version. are written in, keeps its \. It goes in single quotes only when it starts with a sign YAMLYAML Ain't Markup Language A plain-text format, easy for people to read and write, in which rules are written. reads, such as [ (pattern: '[A-Z]{3}\d{3}').

The value is in (or not in) a set of values.

  • Parameters: in, the allowed values, or not_in, the forbidden ones; one of the two. Either is a list of values, { list: name } (a list the datasetDataset One table of a source as Quality Data reads it: a name, its fields and the rules that check them. declares) or { reference: name.Column } (a column of a reference the dataset declares). Values compare trimmed and case-insensitive, unless case: exact.
  • Empty values: skipped; on_empty: fail counts them.
- id: OCC-01
field: Occupation
check: domain
in: { list: income_occupations }
when: HasIncome = 'YES'
alert: The occupation does not generate income
- id: ADV-01
field: AdvisorCode
check: domain
in: { reference: active_advisors.AdvisorCode }
alert: The advisor is not an active one

A list of more than 50 values gets a warning (QR103): make it a catalog table.

The value is within its bounds.

  • Parameters: min, max, at least one; each a number, a date ("2000-01-01"), another field, ":cut" or an expression. Bounds are included; min_exclusive: true or max_exclusive: true leaves them out. A bound on another field makes the ruleRule It applies a pattern to a field; the pattern gives it its dimension and a default severity. The rules that count are the ones on main, the approved version. cross-field.
  • Empty values: skipped; on_empty: fail counts them.
- id: AGE-01
field: age
check: range
min: 0
max: 110
alert: The age is not plausible
- id: ISS-01
field: IssueDate
check: range
min: BirthDate + INTERVAL 18 YEAR
max: ":cut"
alert: The document was issued before 18 or after the cut
- id: EXP-01
field: Expenses
check: range
max: 1.5 * TotalIncome
max_exclusive: true
alert: Expenses far above income: confirm with the client

A date is recent enough, against the cutCut The dataset's data as it was on one date, copied into the lake so it can be measured again without touching the source. Every figure of a report refers to that moment..

  • Parameters: max_age, how old the date may be: a whole number and days, months or years (13 months, 1 year). Fails when the date is before the cut minus max_age.
  • Empty values: skipped; on_empty: fail counts them.
- id: UPD-01
field: LastUpdate
check: fresh
max_age: 13 months
alert: The contact data was not updated in the last year

A total equals its parts.

  • Parameters: parts, a list of fields or expressions, each with its sign ("- Liabilities", in quotes because it starts with -); tolerance, the difference allowed (by default 0). Fails when the field minus the sum of its parts is, in absolute value, over the tolerance.
  • Empty values: skipped when the total is empty; on_empty: fail counts it. A part with no value leaves the record out (it does not apply).
- id: EQ-01
field: Equity
check: sum
parts: [Assets, "- Liabilities"]
tolerance: 1
alert: Equity is not assets minus liabilities

The value does not repeat across records.

  • Parameters: key, the field or fields that must not repeat together (by default the ruleRule It applies a pattern to a field; the pattern gives it its dimension and a default severity. The rules that count are the ones on main, the approved version.’s field); normalize: true, compare letters and digits only, in upper case; ignore, values that may repeat. Values compare trimmed and case-insensitive.
  • Empty values: skipped when the rule’s field is empty; on_empty: fail counts it. Placeholders are not skipped: list them in ignore if they may repeat.
- id: MAIL-02
field: Email
check: unique
normalize: true
ignore: [UPDATE]
alert: The e-mail is shared with another client

Two fields form an allowed combination, from a table the datasetDataset One table of a source as Quality Data reads it: a name, its fields and the rules that check them. declares.

  • Parameters: table, the name of a table under tables:. field is not needed: it is the table’s then.
  • The table: when, the field each row starts from; then, the field whose values the rows allow or forbid; rows, each with when (a value, a list, or "*" for every value no other row names) and allowed or forbidden. One when field for now; a table on several is not compiled yet (QR008).
  • Empty values: skipped when either field is empty. on_empty does not apply.
tables:
occupation_activity:
when: Occupation
then: ActivityCode
rows:
- { when: RETIRED, allowed: ["1000"] }
- { when: [HOMEMAKER, STUDENT], allowed: ["2000"] }
- { when: "*", forbidden: ["1000", "2000"] }
rules:
- id: OCC-02
check: combination
table: occupation_activity
alert: The activity code does not fit the occupation

The last row is the other direction of each pair, in the same table. A record fails once, whichever row it breaks, and the findingFinding A record that fails a rule at a cut. It is resolved when a later cut no longer fails it. says the row.

When one condition holds, another holds too.

  • Parameters: if and then, two conditions; both_ways: true makes it an equivalence (the then also implies the if). field is optional.
  • Empty values: nothing is skipped; the conditions say what an empty value means. on_empty does not apply.
- id: END-01
field: ClosedOn
check: implies
if: Status = 'CLOSED'
then: not is_empty(ClosedOn)
both_ways: true
alert: A closed account needs a closing date, and only closed ones have one

Two fields do not hold the same value.

  • Parameters: from, the other field; normalize: true, compare letters and digits only, in upper case. Values compare trimmed and case-insensitive, unless case: exact.
  • Empty values: skipped when either field is empty; on_empty: fail counts it.
- id: REL-01
field: RelativeDocument
check: differs
from: Document
normalize: true
alert: The relative's document is the client's own

A free condition, for the rare case no patternPattern A reusable way of validating (required, format, fresh and eleven more). Each rule is a pattern applied to a field with its condition. covers. Each one is reviewed.

  • Parameters: fails, the condition under which the ruleRule It applies a pattern to a field; the pattern gives it its dimension and a default severity. The rules that count are the ones on main, the approved version. fails (an expression); dimension, required, since there is no pattern to take it from: completeness, consistency, accuracy, validity, timeliness or uniqueness. field is optional.
  • Empty values: nothing is skipped. Say what an empty value means in the condition, or in a population that leaves it out. on_empty does not apply.
- id: EQ-02
field: Equity
check: expression
fails: Equity < 0
dimension: accuracy
severity: minor
alert: Negative equity

Government Data · Guide v0.8.1