Start studying
Module 7 · Data Cleaning Module contents
Module 7  ·  Card 12 / 13intermediate

Data Validation Rules

A data validation rule is a check that every row must pass, written down so it can run automatically.

Rules cover ranges, allowed values, formats, uniqueness and relations between columns.

For example, a delivery date must not be earlier than its order date, and a quantity must be a whole number above 0.

Rules run every time new data arrives, and failing rows are reported or held back instead of quietly loaded.

Validation catches known problems only, so profiling is still needed to find the ones nobody wrote a rule for.

Learn in depth ↓
Module 07 · Data Cleaning · 13 concepts
In depth  /  15 lines

Data Validation Rules, in more detail

Validation rules turn knowledge about what the data should look like into checks that run without a person.

They exist because the same problems return with every new file, and nobody can inspect every load by hand.

A rule that fails loudly is cheaper than a wrong number that reaches a report.

Range rules set limits, such as an age between 0 and 120 or a discount between 0% and 100%.

Set rules list the allowed values, such as order statuses limited to placed, shipped, delivered and returned.

Format rules check patterns, such as the shape of a UK postcode or an email address containing exactly one @ sign.

Uniqueness rules check that an identifier such as an order number appears only once.

Cross-column rules check relations, such as a refund never exceeding the original payment.

Cross-table rules check that every order points to a customer that exists, which catches broken joins early.

Each rule needs an action on failure: stop the whole load, hold back the failing rows, or let them in with a warning.

Rules that are too strict block good data whenever the business changes, such as when a new order status appears.

Rules that are too loose pass everything, so rules need review as the data and the business change.

Libraries such as Great Expectations and pandera let teams write rules as code and keep them with the rest of the project.

A record of how many rows failed each rule, over time, shows whether a source is getting better or worse.

The usual mistake is writing rules only after a bad number has been published, then never adding more.

Want the full technical article? Wikipedia ↗
Test yourself

One question on this card. Every option explains itself once you pick, right or wrong.

Question 1
A nightly load of delivery data must catch rows where the delivery date is earlier than the order date. What is the best way?
Data Cleaning

13 concepts in this module, then a graded test with every answer explained.

Study this module →
↑↓ move↵ openesc close