The Data Engine
From traces to labels to golden sets, synthetic data and provenance.
Chapters 23 and 24 produce a steady stream of material: traces, feedback, failures, judged samples. A data engine is the machinery that turns that stream into labeled data, and labeled data into test sets, training sets and better judges. Everyone rents the same models, so this machinery, and the data it accumulates, is where an AI product’s advantage compounds.
The chapter covers choosing what to label, getting labels people agree on, generating synthetic data without poisoning yourself, finding duplicates, removing personal data, and recording where every record came from. Its experiments are simulations of annotation and of training on generated data, and a real measurement of four duplicate detectors.
25.1The loop, made concrete
Every stage has an input, an output and an owner.
Each arrow is a job someone owns, with a cadence: a weekly review session, a monthly refresh of the test set, a quarterly re-sample from production. A loop that nobody owns stops turning after the first enthusiastic month.
The split at the end matters most. One labeled record can become a test case or a training example, never both. If the same data trains the system and grades it, the grades stop meaning anything (section 25.7).
Common take“We have lots of logs, so we have lots of data.”
Sharper take“Logs are raw material. Data is what comes out after sampling, labeling, scrubbing and deduplication, with a record of where each item came from and what it’s allowed to be used for.”
25.2Choosing what to label
Mix random samples, which measure, with targeted ones, which find failures.
Labeling is the expensive step, so the choice of what to label decides what the budget buys. Two streams serve different purposes and should be kept apart.
- A random stream measures rates. Only a random sample can say what share of traffic fails, and it keeps the test set looking like real traffic.
- A targeted stream finds failures quickly: traces with a thumbs-down, a retry or a rephrase (section 24.4), traces a judge failed or scored with low confidence, traces where two models disagree, and traces from new slices such as a new language or customer segment.
A targeted stream is full of failures by design, so its failure rate says nothing about the product’s. Record which stream each item came from, and compute rates only from the random one. A common split is about a third of the labeling budget on random samples and the rest on targeted ones, shifting toward random once the obvious failures are fixed.
Common take“We label the conversations users flagged.”
Sharper take“Those find failures fast, but their failure rate tells us nothing about traffic. A random stream runs alongside, and every label records which stream it came from.”
25.3Guidelines and annotators
A label is only as consistent as the document behind it.
Two careful people given a vague instruction produce different labels. Agreement comes from the guidelines, which are a living document with a fixed structure.
- The question, one per task, answerable pass or fail where possible (section 23.2).
- A definition, in a sentence or two.
- Examples of each answer, including near misses that look like passes but are not.
- Edge cases and rulings: a log of every disagreement that was settled, and how. This section grows fastest and is read most.
Before labeling at volume, run calibration rounds: everyone labels the same fifty items, the disagreements are discussed, the guidelines are amended, and the round repeats until agreement stops improving.
Who labels depends on the question. Domain experts are needed wherever correctness needs expertise: law, medicine, your own product’s policies. General annotators can handle questions anyone can judge, such as tone or whether the question was answered. A model can pre-label to save time, with people correcting; measure how often they accept the pre-label unchanged, because a high rate can mean the model is right or that people have stopped checking. Open-source tools such as Label Studio and Argilla provide the queues and interfaces; for complicated traces, the custom review screen of section 24.9 is often better.
Common take“The task is obvious; annotators don’t need much instruction.”
Sharper take“Obvious tasks produce the most confident disagreements. We write examples of each answer, run calibration rounds until agreement levels off, and log every ruling in the guidelines.”
25.4Agreement and adjudication
Pay for a second opinion where people disagree, not everywhere.
Measure agreement between annotators with Cohen’s kappa (section 23.7), and keep measuring it. Hidden gold items, already labeled by an expert and mixed into every annotator’s queue, show who is drifting.
Labels can be bought in several arrangements. To compare them I simulated 10,000 binary labels: 80% of items are clear, where an annotator is right 93% of the time, and 20% are hard, where an annotator is right 65% of the time. An expert, three times as expensive per item, is right 97% and 85% of the time on the same two kinds.
All items
Hard items only
Adding annotators helps, but the vote of three is weakest exactly where help is needed: on hard items two people often make the same mistake. Sending only the disagreements to an expert is both more accurate and cheaper, because annotators disagree on a fifth of items and the expert sees only those. The adjudicated items are also the best material in the dataset: each is an edge case whose ruling belongs in the guidelines.
Common take“Three annotators and a majority vote gives clean labels.”
Sharper take“Majorities fail on hard items, where annotators make the same mistake. Two annotators, with an expert ruling on their disagreements, did better for less in simulation, and every ruling improves the guidelines.”
25.5Synthetic data
Cheap coverage, with a bias toward what the generator finds easy.
Synthetic data is data a model generates. It serves two different purposes, with different rules.
| For test sets | For training | |
|---|---|---|
| Purpose | Coverage of situations rare or absent in traffic | More examples of a behavior, or a stronger model’s behavior in a cheaper model |
| Method | Dimensions and combinations, one request per combination (section 23.4) | Distillation from a stronger model (section 10.9), self-generated variations, answers kept only if a checker accepts them |
| Main risk | Cleaner and more polite than real requests, so scores come out too high | Narrowing: the student learns the teacher’s habits and loses the variety of real data (section 25.6) |
| Rule | Tag it, report it separately, never let it replace real cases | Filter with checks, mix with real data, measure on real cases |
The strongest synthetic training data passes through a checker: code that runs tests, a calculator that verifies the arithmetic, a validator that checks the extracted fields. Generate many answers and keep the ones that pass, the same “sample and check” of section 10.3. Without a checker, filter with a judge, and calibrate that judge like any other (section 23.7).
Read the terms before training on a provider’s outputs. Several major providers’ terms forbid using outputs to build competing models, and enterprise contracts may limit what customer data can be used for (section 25.9).
Common take“We’ll generate ten thousand training examples with the big model.”
Sharper take“We’ll generate them, keep only those a checker accepts, mix in real examples, and measure on real cases. And we’ll read the provider’s terms first.”
25.6Model collapse
Train on your own output long enough and the rare cases disappear.
A 2024 study in Nature by Ilia Shumailov and colleagues showed that models trained repeatedly on the output of earlier models lose the tails of the original distribution: rare phrasings, rare facts, rare kinds of request. The mechanism is simple enough to simulate. My “model” is a distribution over 1,000 phrasings with a long tail, like real language. Each generation draws 5,000 samples from the previous model, with the slight preference for likely outputs that any sampling below temperature 1 or any top-p cutoff introduces (section 2.6), and fits the next model to them. Three regimes ran for 30 generations.
- replace with generated data
- half generated, half fresh real
- accumulate, keeping earlier data
Replacing the data each generation lost almost everything: of 680 phrasings present at the start, 22 survived, and the 900 rarer phrasings, 24% of the original probability, fell to 0.2%. A phrasing that happens not to be sampled in one generation is gone for good, and the preference for likely outputs speeds the loss. Even with no such preference, sampling chance alone took 676 phrasings down to 114. Mixing half fresh real data into every generation held the loss to a few percent. Accumulating, keeping all earlier data and adding the new, lost no phrasings at all, though the rare ones still shrank from 24% of the mass to 18%; a 2024 study by Matthias Gerstgrasser and colleagues found the same protection from accumulating in real models.
The practical rules: keep real data in every training mix, keep earlier data instead of replacing it, and measure on real cases. A model that scores well on synthetic tests and worse on real ones is showing the first sign.
Common take“Synthetic data is unlimited, so we can keep generating our way to better models.”
Sharper take“Each round of self-generated data trims the rare cases, and those are where products fail. I keep real data in every mix, accumulate instead of replacing, and judge every round on real cases.”
25.7Duplicates and contamination
Exact matching misses copies; word overlap misses paraphrases and flags templates.
Duplicates do two kinds of damage. In training data they make a model memorize the repeated items and spend capacity on them; a 2022 study by Katherine Lee and colleagues found that deduplicating training data reduced memorized output and improved models. Between training data and test sets they are contamination: the test then measures recall, not ability (section 23.4).
Detectors differ in what they can see. I built 40 test requests from one template, made four kinds of copy of each, and ran four detectors over them. I also checked each detector on pairs of genuinely different requests from the same template, which it should not flag.
| Detector | Exact copy | Case and spacing | Small edit | Paraphrase | A different request, same template |
|---|---|---|---|---|---|
| Exact hash | all 40 | none | none | none | none |
| Normalized hash | all 40 | all 40 | none | none | none |
| Any shared 13-word sequence | all 40 | all 40 | all 40 | none | flagged all pairs |
| Word-trigram overlap ≥ 0.5 | all 40 | all 40 | all 40 | none | flagged all pairs |
Exact hashing catches only identical text. Normalizing case, punctuation and spacing first adds cheap coverage. Word-sequence overlap, either a shared 13-word sequence, the test used when GPT-3 was checked for contamination, or a high share of shared word triples, catches edited copies, but no paraphrase, and it flagged every pair of different requests, because requests built from one template share long runs of words. Synthetic test sets are exactly where that happens.
The workable pipeline runs in layers: normalized hashes to remove exact copies; word-overlap methods such as MinHash, which estimates the share of shared word sequences quickly at scale, for near copies; embedding similarity (section 14.1) for paraphrases; and a person or a calibrated judge for the borderline pairs each layer flags. Run it in both directions: within the training data to remove repeats, and between training data and every test set before any training run.
Common take“We hashed the test set against the training data, so there’s no contamination.”
Sharper take“A hash only finds identical text. An edited copy or a paraphrase sails through. I add word-overlap for near copies and embeddings for paraphrases, and review what they flag.”
25.8Personal data
Patterns catch formats; names and context need more.
Traces carry what users typed, and labeled data is built from traces, so personal data flows into test sets and training data unless it is removed on the way. Removal comes in layers.
| Method | Catches | Misses |
|---|---|---|
| Patterns and checksums | Email addresses, phone numbers, card numbers (with the Luhn check), national ID formats | Anything without a fixed format |
| Named-entity recognition, as in the open-source Presidio | Names, places, organizations | Unusual names, and personal details in ordinary words |
| A model asked to find personal data | Context: “my daughter’s school in Leeds”, health conditions, account details described in words | Costs a model call per record; must itself be measured |
Replace what is found with consistent placeholders, so that the same name becomes the same token everywhere in a record: “[PERSON_1] asked [PERSON_2] to forward the invoice” still teaches the model something, where blanks do not. Keep the mapping, if you keep it at all, apart from the data and under stricter access.
Scrubbing reduces risk but does not remove it. Combinations of ordinary details, a job title, a town and a date, can still identify someone. So scrubbed data keeps its access controls and retention limits, and deletion requests must be able to find it, which is the job of provenance (Chapter 27).
Common take“We run a regex over the data to remove personal information.”
Sharper take“Patterns catch emails and card numbers, not names or ‘my neighbor’s pharmacy’. I layer patterns, entity recognition and a model, use consistent placeholders, and still treat the result as sensitive.”
25.9Provenance and licensing
Record where every item came from and what it may be used for.
Every record in a dataset should carry its history.
{
"id": "case-20931",
"source": "production trace t_8812, tenant 44",
"collected": "2026-09-14",
"consent_basis": "customer contract section 7.2: quality improvement, no model training",
"allowed_uses": ["evaluation"],
"transformations": ["pii_scrub v3", "dedup 2026-10", "label: refund_policy_v2 guidelines"],
"labels": [{"by": "annotator_17", "value": "fail"}, {"by": "expert_2", "value": "fail", "adjudicated": true}],
"dataset_versions": ["golden-2026.10", "golden-2026.11"]
}Four questions depend on it. May we use this? Enterprise contracts often allow customer data for evaluation or support but not for training, and some forbid sending it to particular processors. Can we delete it? A deletion request has to reach every dataset, test set and training set built from a person’s data, which is impossible without a link back to the source. Was it licensed? Text from the web, purchased datasets and open datasets each carry licenses and opt-outs, and providers of general-purpose models in the European Union must publish a summary of their training content (Chapter 27). Which version did that? Every evaluation result should name the dataset version it ran on, so that a change in score can be traced to a change in data rather than in the system.
Dataset versioning tools, from Hugging Face datasets to DVC or lakeFS, make the last one routine. The others depend on recording consent and use at the moment data is collected; reconstructing it afterward rarely succeeds.
Common take“It’s our customers’ data in our database, so we can train on it.”
Sharper take“Only if their contracts allow it, and many limit it to evaluation. Every record carries its source, its permitted uses and its version history, so I can answer that, and honor a deletion, without guessing.”
Key takeaways
- A data engine turns traces into labeled data and labeled data into test sets, judge calibration sets and training data. Each stage needs an owner and a cadence.
- A labeled item becomes a test case or a training example, never both.
- Label a random stream to measure rates and a targeted stream to find failures, and keep track of which is which.
- Consistent labels come from guidelines with examples, edge-case rulings and calibration rounds.
- In simulation, two annotators with an expert ruling on their disagreements reached 95% accuracy at 2.6 times the cost of one annotator; three with a majority vote reached 93% at three times.
- Synthetic data is best when a checker filters it. Tag it, and measure on real cases.
- Training on generated data trims the rare cases. Replacing data each generation kept 22 of 680 phrasings; mixing in real data or accumulating kept nearly all.
- Exact hashes miss edited copies, and word overlap misses paraphrases and flags templated text. Layer the detectors and run them between training and test data.
- Scrub personal data in layers with consistent placeholders, and record every item’s source, permitted uses and versions.
Check your understanding
-
Your team labels only conversations that users flagged, and reports that 41% of conversations fail. Leadership is alarmed. What is wrong with the number, and how do you fix the labeling plan?
Answer outline
Flagged conversations were selected for being bad, so their failure rate is not the product’s. Rates can only come from a random sample. Keep the targeted stream, since it finds failures quickly, but add a random stream with its own share of the budget, tag every label with its stream, and compute rates only from the random one. Report the 41% for what it is: the failure rate among flagged conversations, useful for knowing what to fix first.
-
A fine-tuned support model scores 96% on your test set, up from 88% before tuning. In production, retries and escalations are unchanged. The training data was 20,000 examples generated by a larger model from templates, and the test set was partly synthetic, from the same templates. Diagnose.
Answer outline
Two problems compound. The synthetic test cases share templates with the training data, so the test measures recall of the template’s patterns: contamination that exact hashing would not catch (section 25.7). And synthetic requests are cleaner than real ones, so even uncontaminated synthetic scores run high (section 25.5). Report real and synthetic test cases separately; run near-duplicate and embedding checks between training data and the test set and remove matches; and add real production cases. Expect the real-case score to explain the flat production metrics. Next round, mix real examples into training and filter synthetic ones with a checker.
-
An enterprise customer invokes their contract and asks you to delete all of their users’ data, including from anything you trained. Their conversations went into traces, test cases and two fine-tuning runs. What do you need, and what do you do?
Answer outline
You need provenance: each record’s source tenant, so you can find every trace, test case and training example derived from their data, including scrubbed and transformed copies. Delete or replace them, and record the new dataset versions. Check the contract’s permitted uses: if it allowed evaluation only, the training runs were already a breach to raise with legal. For the fine-tuned models, the dependable remedy is retraining without their data from the recorded dataset version, which is why training sets need versions and why adapters trained per customer (section 17.9) are easier to remove. Without provenance none of this can be done with confidence, which is the argument for recording it at collection time.
Further reading
- Chip Huyen, AI Engineering, chapter 8: dataset engineering, including curation, synthesis and deduplication.
- Chip Huyen, Designing Machine Learning Systems, chapters 3 and 4: data sources, sampling and labeling.
- Shreya Shankar and Hamel Husain, Evals for AI Engineers (O’Reilly, 2026): the sections on synthetic data and on collaborative labeling.
- Ilia Shumailov and others, “AI models collapse when trained on recursively generated data” (Nature, 2024), with Matthias Gerstgrasser and others, “Is Model Collapse Inevitable?” (2024), on why accumulating data avoids it.
- Katherine Lee and others, “Deduplicating Training Data Makes Language Models Better” (2022).