Skip to content

Tutorial: your first rules

This tutorial writes the 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. of one field, then a few more, explaining each choice as it comes. It takes about half an hour. By the end you will know how a rule is read, why it fails, passes or does not apply, and how it reaches main.

Every key used here is described in Rule language, and every patternPattern A reusable way of validating (required, format, fresh and eleven more). Each rule is a pattern applied to a field with its condition. in Rule patterns. The datasetDataset One table of a source as Quality Data reads it: a name, its fields and the rules that check them., its fields and its values are synthetic.

A dataset of customers, clients, whose mappingMapping How a dataset's table is read: which column each field reads and its type, the record key, each field's priority and the roles of some fields. has these fields:

Field Holds
ClientType PERSON or COMPANY
Mobile A mobile phone number
Occupation EMPLOYEE, STUDENT, RETIRED…
Employer The employer’s name, for employees
BirthDate The customer’s birth date
LastUpdate When the customer’s data was last updated
HasIncome YES or NO
Status ACTIVE or CLOSED
ClosedOn When the customer’s account was closed
RepDocument A company’s legal representative’s document

The 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. check the dataset at a cut: the date its data was taken. Keep that in mind; it comes back in step 6.

  • The datasetDataset One table of a source as Quality Data reads it: a name, its fields and the rules that check them. is mapped: its fields are in the Explorer, under Lake. MappingMapping How a dataset's table is read: which column each field reads and its type, the record key, each field's priority and the roles of some fields. a table is done once, by whoever manages datasets, and it takes the dataset’s first 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. by itself, so Test has data to run on: see Map a table into a dataset.
  • If the data of that first cut could not be extracted, Test says the dataset has no cut extracted yet: take one with Run now, under the dataset’s Cuts, as Run and schedule cuts explains.
  • Your permissions: Edit rules on the dataset to write 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. (without it, the + beside a field does not show); Approve rules and mappings and Manage datasets to deploy to main. With only the first, you save draftsDraft A change to a dataset's rules kept apart from main, usually saved by an author who may edit rules but not approve them, until someone who may approve reviews it and approves or discards it. that someone else approves.

Each field has its own 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. file, named as the field: Mobile.yaml. In the Explorer, + beside Mobile opens it (new if there is none) with a rule ready to fill. A file always starts by naming its datasetDataset One table of a source as Quality Data reads it: a name, its fields and the rules that check them.:

dataset: clients
rules:
dataset: clients
rules:
- id: MOB-01
field: Mobile
check: required
alert: The client has no mobile number

Four keys, and each says one thing:

  • id names the rule for good. Results are kept by it over time, so keep it when the rule changes.
  • field is the field it checks.
  • check is the pattern: here required, the field has a value.
  • alert is what the person who fixes the record reads. Write it for them.

Nothing else is needed: required already has a dimensionDimension The kind of quality a rule measures (completeness, validity, timeliness…), given by its pattern. (completenessCompleteness Quality dimension: the data is present when it must be.) and a 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. (blocking). Empty means no value, an empty text, or only spaces; a filler the datasetDataset One table of a source as Quality Data reads it: a name, its fields and the rules that check them. declares, such as UPDATE, counts as empty too.

Look at As read beside the editor: it says the rule in words. Read it every time you write one; it is the quickest way to catch a rule that does not say what you meant.

- id: MOB-02
field: Mobile
check: format
pattern: \d{10}
alert: The number does not have ten digits

format takes your own pattern, a regular expression that must match the whole value (here, ten digits), or a named format Quality Data maintains, such as email.

Notice what happens with an empty mobile: MOB-01 fails, and MOB-02 does not apply. Every rule gives one of three results for a record: it fails, it passes, or it does not apply. PatternsPattern A reusable way of validating (required, format, fresh and eleven more). Each rule is a pattern applied to a field with its condition. other than required skip an empty value, so a missing mobile is counted once, by the rule that exists for it.

- id: MOB-02
field: Mobile
check: format
pattern: \d{10}
alert: The number does not have ten digits
examples:
fails: [{ Mobile: "12345" }, { Mobile: "555010123A" }]
passes: { Mobile: "5550101234" }
skips: { Mobile: null }

examples are records the rule must fail, pass and skip. Writing them makes you say what the rule must do, and tells whoever reviews it the same; the editor does not run them yet, so check the rule’s behaviour with Test (step 10). Write at least one of each for any rule with a condition.

5. A rule with a condition: the employer of an employee

Section titled “5. A rule with a condition: the employer of an employee”

Only employees have an employer. A rule for Employer, in Employer.yaml:

dataset: clients
rules:
- id: EMP-01
field: Employer
check: required
when: Occupation = 'EMPLOYEE'
severity: major
alert: The employer is missing for an employee
examples:
fails: { Occupation: EMPLOYEE, Employer: "" }
passes: { Occupation: EMPLOYEE, Employer: ACME LTD }
skips: { Occupation: STUDENT, Employer: "" }
  • when is a condition in plain SQLStructured Query Language The standard language for querying databases; the platform turns each rule into SQL for the engine that runs it. (Structured Query Language). Where it does not hold, the rule does not apply: a student without an employer is not a failure.
  • severity: major changes the patternPattern A reusable way of validating (required, format, fresh and eleven more). Each rule is a pattern applied to a field with its condition.’s default (blocking): the record is usable, with reservations. 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. weights a failure in the indicators.
  • Texts compare trimmed and without telling upper from lower case, so 'employee ' matches as well.

If many rules share a condition, such as “only people”, declare it once as a population in the datasetDataset One table of a source as Quality Data reads it: a name, its fields and the rules that check them.’s global rulesGlobal rules A dataset's file reglas_globales.yaml: what several fields share, such as lists, populations and named rules, declared once for every rules file of the dataset., reglas_globales.yaml:

dataset: clients
populations:
individuals: ClientType = 'PERSON'

Then any rule says population: individuals. With both when and population, both must hold.

The customer’s data must have been updated within the last 13 months, in LastUpdate.yaml:

dataset: clients
rules:
- id: UPD-01
field: LastUpdate
check: fresh
max_age: 13 months
alert: The contact data was not updated in the last year

“Within the last 13 months” means before the cut, never before today. A cut measured again next year gives the same result. When you need the cut in an expression, write :cut; as a bound alone, quote it:

- id: BIR-01
field: BirthDate
check: range
min: "1900-01-01"
max: ":cut"
alert: The birth date is not plausible

The occupations that come with an income, declared once in the global rulesGlobal rules A dataset's file reglas_globales.yaml: what several fields share, such as lists, populations and named rules, declared once for every rules file of the dataset.:

lists:
income_occupations: [EMPLOYEE, SELF-EMPLOYED, RETIRED]

and checked in Occupation.yaml:

- id: OCC-01
field: Occupation
check: domain
in: { list: income_occupations }
when: HasIncome = 'YES'
alert: The occupation does not generate income

A short list can go inline (in: [EMPLOYEE, RETIRED]). Over 50 values, lint asks you to make it a catalog table (QR103).

Some checks are about two fields together. implies says: when one condition holds, another holds too.

- id: END-01
field: ClosedOn
check: implies
if: Status = 'CLOSED'
then: not is_empty(ClosedOn)
alert: A closed account needs the date it was closed

implies skips nothing: its conditions decide what an empty value means, so say it with is_empty(x). As read marks the rule as cross-field, because it reads more than its own field.

9. Write a check once, use it in many fields

Section titled “9. Write a check once, use it in many fields”

Several fields hold documents with the same form. Write the check once as a named rule in the global rulesGlobal rules A dataset's file reglas_globales.yaml: what several fields share, such as lists, populations and named rules, declared once for every rules file of the dataset.:

named:
valid_document:
check: format
pattern: \d{5,12}
severity: major
alert: The document has 5 to 12 digits

and start each field’s 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. from it with extends, changing only what differs:

- id: REPDOC-01
field: RepDocument
extends: valid_document
when: ClientType = 'COMPANY'

A change to valid_document changes every rule that extends it, at the next 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.. Before you change or remove one, read Share rules across fields.

Fix what lint marks, choose Test to run the file on the latest 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., and read the counts: if a 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 on half the datasetDataset One table of a source as Quality Data reads it: a name, its fields and the rules that check them., read it again. Then choose Deploy, or Save as a draft if you may not approve. How each step goes, and what it can refuse, is in Write, change and test a rule and Take a change to main. The rules on main are the ones the next cut is evaluated with.

You wrote What happens Write instead
required and on_empty: fail together Lint error: it does not apply required alone
A date compared with today Not possible :cut
max: :cut unquoted YAMLYAML Ain't Markup Language A plain-text format, easy for people to read and write, in which rules are written. reads it as something else max: ":cut"
A new id after changing a 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. Its history starts again Keep the id
A rule in another field’s file Lint warning QR210 Move it to its field’s file
No alert Lint warning A sentence for whoever fixes the record
  • Rule language: every key, expressions and their functions, and what Quality Data decides for 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..
  • Rule patterns: the fourteen patternsPattern A reusable way of validating (required, format, fresh and eleven more). Each rule is a pattern applied to a field with its condition., one by one.
  • Lint findings: every message of the editor’s checker.
  • The Tasks pages, from Write, change and test a rule to Export and import rules: sharing rules, draftsDraft A change to a dataset's rules kept apart from main, usually saved by an author who may edit rules but not approve them, until someone who may approve reviews it and approves or discards it., history.

Government Data · Guide v0.8.1