The quality checks that run before any training run
Chapter 21 taught eval-first for model outputs. The same reflex applies one step earlier: check the dataset before you trust it. Every check is a one-line query, and together they take five minutes that regularly save a week.
Run the editor. Five queries, five verdicts on a tiny table — and this toy already fails three of them.
The checklist, as SQL
- Row count vs expectation.
COUNT(*). You expected ~10k users and got 130k? A join exploded upstream (last lesson). - Duplicates.
COUNT(*)vsCOUNT(DISTINCT ...). Exact dupes double-weight those rows in training; near-dupes across your train/test split are leakage — the model gets quizzed on rows it memorized. - Missingness per column.
COUNT(col)vsCOUNT(*)(aggregates skip NULLs — last lesson's rule, now working for you). - Label balance. For a 0/1 label,
AVG(label)is the positive rate. If it's 0.02, accuracy is the wrong metric and chapter 41 explains what to use instead. If it's 0.5 exactly on real-world churn data, be suspicious of the query, not pleased. - Range sanity.
MIN/MAXper numeric column. Negative ages, million-dollar coffees, timestamps from 1970 — outliers and unit mistakes show up here first.
Make it a gate, not a vibe
The checks earn their keep when they run every time the dataset is rebuilt — the same ratchet logic as chapter 30. Wrap them in a script that fails loudly when a check is violated, and put it between "query ran" and "training started." A dataset that skipped its checks is a dataset with unknown bugs, which chapter 24's Klarna-style postmortems taught you is how confident wrong systems ship.
Where AI specifically gets this wrong
- Generating the query and moving on. Cursor writes plausible SQL; it does not know your expected row count or label rate. Those expectations live with you — write them into the checks.
- Deduping blindly.
SELECT DISTINCT *as a "fix" can delete legitimately repeated events (two identical coffee purchases are real). Distinguish "duplicate rows" from "repeated events" with a proper event id before deleting anything.
And the quiet one: checking once, ever. Data changes. A check that ran in March proves nothing about the June rebuild.