Deployed Lab

Module 3 · Data you can trust · Chapter 20 · Free

Data quality and validation

13 min1 clickable picture1 validation lab7 checks5-min video review
In 30 seconds

Picture: a bouncer at the door of a library, checking every box of books before it goes on the shelves.

The problem Kavish ships a support assistant (a composite example) trained on 12,400 exported support tickets. Week one looks great. Week three, it tells a customer refunds close in 14 days. The current policy says 30. Nobody changed the model. The export had quietly filled with old tickets: 992 rows (8 percent) were duplicates, and 640 tickets still carried a retired policy label from 2023. The assistant read the mess and reported it, fluently. The data was the product. The model was only the messenger.
The plan for this chapter
  1. How bad data poisons an AI system, with real-feeling numbers.
  2. The five validation checks, and what each one catches.
  3. One row's journey through the validation gate.
  4. A lab: run the checks yourself on a small table.
  5. The fix order, and how to keep the data clean.

After this chapter you can:

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:

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:

  1. 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".
  2. 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.
  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.
  4. Duplicates: does each real thing appear once? Catches double exports, retried uploads and joins that quietly multiply rows.
  5. 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.

The validation gate A batch arrives from the source system. It passes a schema check, then range and freshness checks, then duplicate and null checks. Rows that pass go to the clean store the AI reads. Rows that fail drop down to quarantine, where a human can inspect and repair them. Source batch12,400 rows Schema checkshape and values Ranges andfreshnessbounds and dates Duplicatesand nullsonce, and filled Clean storewhat the AI reads Quarantineinspect and repair
  1. An export lands: 12,400 rows. Nothing in it has been trusted yet. Arrival is not approval.
  2. Columns, types and allowed values are compared with the written schema. A new status like "resolved" fails loudly here instead of silently later.
  3. Numbers must sit inside their bounds, and rows must be recent enough. The score of 9 and the ticket from May both stop here.
  4. Each id may appear once, and required fields must be filled. The second copy of T-101 and the blank email stop here.
  5. Only rows that passed every check reach the clean store, the one place the AI system reads from.
  6. Failures are kept, counted and reported. A human repairs the cause, not just the row.
SourceChecksQuarantineClean data

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.

In the field A support team (composite) added these five checks to a nightly export of 48,000 rows. Night one quarantined 3,900 rows, about 8 percent, and the team braced for complaints. Instead, wrong-policy answers in their weekly sample fell from 11 in 50 to 2 in 50 within a fortnight. The model never changed. The gate did.

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:

  1. 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.
  2. 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.
  3. 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

Recap

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.

Review