Data Validation & Quality Checks
P12.data-quality-sql.04 · Audience: guest, it-ml, language-pro · Prerequisites: SQL for Analytics I — Select, Filter, Group
The last three modules assumed the data was clean. It never is. A null where a city should be, a negative quantity, a product listed twice, an order pointing at a product that does not exist — each is a small corruption that, as the joins module showed, can ride silently into a total and out the other side as a plausible wrong number. Validation is the discipline of catching those corruptions on purpose, at the door, and refusing to let a bad batch through quietly. This module builds the four rule types that catch the overwhelming majority of data defects, runs them on the deliberately-corrupted retail dataset, and makes the case for the loudest possible failure.
There is a temptation, when a pipeline meets a bad row, to be forgiving: skip it, coerce it, fill in a default, keep going. That instinct is exactly backwards. A row that is silently dropped or quietly patched becomes a discrepancy nobody can explain three weeks later — the revenue is off by a bit, and the reason is buried in a coercion no log recorded. The engineering virtue is the opposite: fail loudly. Detect the violation, name it, and stop — or at minimum, quarantine the batch and alert a human.
ⓘ Concept: Loud failure is cheaper than silent corruption
Why it matters — A pipeline that halts on bad data costs you an alert and an hour; a pipeline that swallows bad data costs you a wrong decision and a week of forensic archaeology to find out why. Silent handling — the try/except that logs nothing, the fillna that hides a missing join — trades a visible problem now for an invisible one later, and the later one is always more expensive because the evidence has scattered. Validation is the practice of paying the small, loud cost up front, on purpose.
🗣️ From a linguist's perspective: The smoke detector you don't disconnect
Ask the mentor about this module
Ask a question about this content. The mentor explains and grounds its answer in what you are studying; asking is recorded as a learning signal, not a grade.
🎓 Practice ladder
4 graded rungs · ~40 minNow catch the defects yourself. Each rung is a three-panel workspace: instructions on the left, a code editor in the middle, output and test results on the right. Run checks the visible tests; Submit grades against hidden edge cases. The explorer rung profiles the corrupted batch and asks which column fails the range rule; the practitioner rungs implement the rules and handle referential integrity's asymmetry; the senior rung composes them into a configurable quality gate.
Rung 1 — Count the damage (explorer)
Loading exercise…
Rung 2 — Write the rules
Loading exercise…
Rung 3 — Referential integrity
Loading exercise…
Rung 4 — The quality gate (senior)
Loading exercise…
Try it yourself
A scratch console for this page's ideas — ungraded, nothing you run here is recorded.
Scratch console
A scratch console with the scientific stack (pandas, numpy, scikit-learn). Runs on the server — no network, resource-limited and measured.
Output appears here.
Where next?
Later in Data Quality & SQL
Go up a level