Module 3 · Data you can trust · Chapter 20 · Free
Data quality and validation
- Most "AI mistakes" start as data mistakes the model faithfully repeated.
- Five cheap checks catch most of them: schema, ranges, freshness, duplicates and nulls.
- Fix in order: stop the bad inflow, quarantine the damage, then clean.
Picture: a bouncer at the door of a library, checking every box of books before it goes on the shelves.
- How bad data poisons an AI system, with real-feeling numbers.
- The five validation checks, and what each one catches.
- One row's journey through the validation gate.
- A lab: run the checks yourself on a small table.
- The fix order, and how to keep the data clean.
After this chapter you can:
- Name the five ways data usually goes bad, and the check that catches each.
- Run a validation pass by hand and count failures per check.
- Explain why you stop the inflow before you clean anything.
Next: the words you will see.
Words you'll meet
- Data quality
- Whether the data is fit to use: right shape, current, complete, and true. Example: a ticket table where every row is a real, distinct ticket.
- Validation
- Checking data against written rules before it is used. Example: "status must be open, pending or closed" is a rule a script can test.
- Schema
- The expected shape of the data: column names, types and allowed values. Example: a column called csat that holds a whole number.
- Range check
- A rule that a value sits between a low and a high bound. Example: a satisfaction score of 9 fails a 1 to 5 scale.
- Freshness
- How recent the data is, against a stated limit. Example: rows updated more than 90 days ago count as stale.
- Duplicate
- The same record stored more than once. Example: ticket T-101 appearing twice in one export.
- Null
- A missing value where one is required. Example: a ticket with no customer email, so nobody can reply to it.
- Label
- A tag a human or a system put on a record. Example: "policy v1" on a ticket. Wrong labels teach wrong answers.
- Quarantine
- A holding area for rows that fail checks, kept out of the live system but not deleted. Example: a quarantine table you can inspect and repair.
- Silent schema change
- An upstream change nobody announced, like a renamed column or a new status value. Example: "closed" becomes "resolved" overnight and every filter misses it.
- Source of truth
- The one place a fact is decided. Example: the policy document, not the tickets that mention it.
Next: how a clean-looking export poisoned an assistant.
Step 1: Why bad data beats a good model
Kavish's team did everything the earlier chapters suggest. The assistant used retrieval (Chapter 9), the chunks were sensible, and the evals (Chapter 18) passed on launch day. Then the answers rotted, slowly, because the data underneath kept moving and nobody was watching it.
When they finally audited the 12,400 ticket export, they found four separate faults:
- Duplicates: 992 rows, 8 percent of the export, were copies. Popular old tickets appeared two or three times, so retrieval kept surfacing them. A repeated wrong answer starts to look like a consensus.
- Stale rows: 640 tickets still described refund policy v1, retired in 2023. They were never wrong when written. They were wrong now, and nothing marked them as old.
- Wrong labels: about 300 tickets were labelled "billing" when they were really login problems, so routing and reporting both drifted.
- A silent schema change: the helpdesk tool added a new status, "resolved", next to "closed". Reports that counted closed tickets quietly lost a fifth of their rows.
Notice what is missing from that list: the model. Swapping in a bigger model would have produced the same wrong refund window, in nicer sentences. Embeddings (Chapter 8) capture the meaning of the text they are given. Given duplicated, stale, mislabelled text, they capture that faithfully too.
The rule of this chapter: when an AI answer is wrong, check the data before you touch the prompt, the model or the retrieval settings. Data faults are the most common cause, and the cheapest to prove.
Next: the five checks that catch these faults.
Step 2: The five checks
Validation means writing your expectations down as rules, then testing every batch against them before the batch is used. Five checks cover most of what goes wrong in practice:
- Schema: are the columns the ones you expect, with the right types and allowed values? Catches silent schema changes and stray values like a status of "done".
- Ranges: does every number sit inside its sensible bounds? Catches the satisfaction score of 9, the discount of 140 percent, the age of minus 3.
- Freshness: is every row recent enough for its job, and is the batch itself on time? Catches stale policies and a feed that stopped arriving on Tuesday.
- Duplicates: does each real thing appear once? Catches double exports, retried uploads and joins that quietly multiply rows.
- Nulls: are the fields you depend on actually filled in? Catches the missing email, the blank category, the price that never arrived.
Written as a checklist a script can run, it looks like this:
Validation rules: support_tickets export export_date: 2026-11-25 schema: columns: [id, customer, category, status, updated, csat, email] status in: [open, pending, closed] ranges: csat between 1 and 5 freshness: updated on or after 2026-08-27 (90 days before export) duplicates: id must be unique nulls: email must not be blank category must not be blank on_fail: send the row to quarantine, count it, report it
Two habits make this work. First, every rule has a number attached, so a run produces counts, not vibes: "14 rows failed freshness" is a fact you can trend. Second, failing rows go to quarantine, not to the bin and not into the live data. You keep the evidence, and the system stays clean while you investigate.
Next: one row's journey through the gate.
Step 3: One row through the validation gate
Every batch passes the same gate before it is loaded, chunked or embedded. Press next to walk a row through it.
On a phone, swipe the picture sideways.
- An export lands: 12,400 rows. Nothing in it has been trusted yet. Arrival is not approval.
- Columns, types and allowed values are compared with the written schema. A new status like "resolved" fails loudly here instead of silently later.
- Numbers must sit inside their bounds, and rows must be recent enough. The score of 9 and the ticket from May both stop here.
- Each id may appear once, and required fields must be filled. The second copy of T-101 and the blank email stop here.
- Only rows that passed every check reach the clean store, the one place the AI system reads from.
- Failures are kept, counted and reported. A human repairs the cause, not just the row.
Where the picture breaks down: validation catches broken shapes, not wrong facts. A ticket can pass every check and still say 14 days, if the source document itself is wrong. That is why the source of truth matters, and why freshness rules retire old policy rows before they can be quoted.
Next: the lab, where you run the gate yourself.
Step 4: Lab: run the checks by hand
Why: counting failures yourself, once, teaches you what each check really catches, and how often one row fails two checks at once.
Here is a small export of 12 support tickets, dated 25 November 2026. The rules are the ones from Step 2: status must be open, pending or closed; csat between 1 and 5; updated on or after 27 August 2026; each id appears once; email and category must not be blank.
Lab: Step 4 of the chapter asks you to run the validation gate by hand on 12 support tickets. This lab runs in your browser and needs JavaScript enabled.
Next: the order to fix things in, because cleaning first does not work.
Step 5: The fix order, and keeping it clean
When a check lights up, the temptation is to scrub the bad rows and move on. Resist it. Cleaning while the tap is still running just gives you a cleaner mess tomorrow. The order that works:
- Stop the inflow. Find where the bad rows are created and fix that first: the export filter, the form that allows a blank email, the sync that writes each ticket twice. Until this is done, every other step is temporary.
- Quarantine what is already in. Move failing rows out of the clean store into quarantine, so the AI stops quoting them today, not after a long cleanup project.
- Then clean, deliberately. Repair what is repairable (the retired policy label), merge what is duplicated, and delete only what you have decided, in writing, is worthless. Quarantined rows are evidence; keep them until the cause is understood.
Then make it stick. Run the checks on every batch, not once. Keep the failure counts per check, per day, in a place someone actually looks. A freshness count creeping up for three days is a feed dying in slow motion. A duplicate count jumping from 4 to 900 overnight is a deploy, not a coincidence. And when you measure retrieval quality (Chapter 29), measure it on the clean store only, or you will spend weeks tuning search against data that should never have been indexed. Document ingestion (Chapter 33) is where this gate usually lives in a pipeline, and it gets a chapter of its own in the retrieval module.
Next: a prediction, two quick checks, then the final quiz.
Stale data is the most common cause, and the cheapest to prove: check the dates on what the system can read before touching the model.
Quick checks
Mix-ups to avoid
- "The model is hallucinating again." Often it is quoting your stale or duplicated data word for word. Check the data first.
- "We cleaned the data last quarter." Data decays daily. Validation is a gate on every batch, not a spring clean.
- "Just delete the failing rows." Quarantine them. Deleted rows teach you nothing, and some were the only copy.
Recap
- The data is the product; the model is the messenger. Bad data in means confident bad answers out.
- Five checks catch most faults: schema, ranges, freshness, duplicates and nulls, each producing counts, not vibes.
- Fix in order: stop the inflow, quarantine the damage, then clean.
Next: Chapter 21, "Pipelines and ETL for AI systems": moving data through this gate on a schedule, without breaking it twice.
Review this chapter in 5 minutes
The five checks, the gate, the lab counts, and the fix order.
Chapter quiz
Four questions. Score 70% or more to mark this chapter complete.