Sub topic 4
Where cases come from
This chapter assumes you can read and write JSONL, call an LLM app from Python, and compute a mean and a proportion. It also assumes you have already defined the task and success criteria, and have a case schema with fields like id, input, reference, tags, source, and difficulty.
An evaluation dataset is only as useful as the cases in it. Where each case comes from decides what the score means. This chapter covers the main sources, what each is good and bad at, and how to record where a case came from so you can reason about your results later.
The three main sources
Most teams draw cases from three places:
- Production logs. Real inputs from users of the app, or from an earlier version of it.
- Expert-written cases. Inputs written by people who know the domain, such as support staff, lawyers, or engineers.
- Synthetic cases. Inputs produced by a model, from templates, or by mutating existing cases.
A fourth source is also common: public benchmarks and open datasets. They are useful for sanity checks, but they rarely match your task closely, and they may already be in a model's training data.
| Source | Strength | Weakness | Best used for |
|---|---|---|---|
| Production logs | Matches the real input distribution | Needs privacy handling, has no labels, underrepresents rare cases | Common cases, realistic phrasing |
| Expert-written | Precise, covers known hard cases, labels come with it | Slow, reflects what experts think users ask | Edge cases, policy rules, adversarial inputs |
| Synthetic | Fast and cheap, easy to scale | Can be repetitive or unrealistic, can inherit model bias | Filling gaps in coverage |
| Public benchmark | Free, comparable across systems | Weak task match, possible contamination | Sanity checks |
No single source is enough. Logs tell you what users do. Experts tell you what matters. Synthetic generation fills the holes that neither covers.
Production logs
Logs are the best evidence of what users really send. They contain typos, mixed languages, vague questions, pasted emails, and requests you never planned for. Expert-written cases rarely look like this.
Sampling
Do not take the first 500 rows. Logs are usually ordered by time, and one busy day or one incident can dominate. Sample deliberately:
- Random sample for a faithful picture of the common traffic.
- Stratified sample when you want fixed numbers from groups, for example by language, feature, or customer tier.
- Targeted sample for known trouble: conversations with thumbs-down feedback, escalations to a human, retries, or very long inputs.
A random sample alone will miss rare but important inputs. A targeted sample alone will make the app look worse than it is in normal use. Tag each case with how you sampled it, so you can separate the two later.
Privacy and consent
Logs often contain names, emails, account numbers, and health or payment details. Before a log line becomes a test case:
- Remove or replace personal data. Replace values with realistic placeholders, such as
[email protected], so the input still looks like real text. - Check your data retention and consent rules. Some logs may not be reusable for testing.
- Limit who can read the dataset. A dataset built from logs inherits the sensitivity of the logs.
Logs have no answers
A log records the input and what the app said. It does not record the right answer. The app's past output may be wrong, so do not copy it into reference as if it were correct. Labeling comes later in this tutorial. For now, store the log line as an input with an empty or pending reference.
Dedupe and near-duplicates
Real traffic repeats. "Where is my order?" may appear thousands of times. If you sample at random and keep every copy, a handful of common phrasings can fill the dataset, and a score then mostly measures those. Remove exact duplicates, and consider collapsing near-duplicates by normalizing case and whitespace.
import re
def normalize(text):
return re.sub(r"\s+", " ", text.strip().lower())
def dedupe(candidates):
seen = set()
kept = []
for c in candidates:
key = normalize(c["input"])
if key in seen:
continue
seen.add(key)
kept.append(c)
return keptThis catches exact duplicates after normalization. It does not catch paraphrases. For those, you need embedding similarity or manual review, and for small datasets manual review is usually enough.
Expert-written cases
Domain experts know where the app is likely to fail, and they can write the reference answer as they write the question. This source costs the most per case, so spend it where it counts:
- Policy boundaries. The 30-day return window: what happens on day 30, day 31, or when a laptop arrives late?
- Rules with exceptions. Cases where the obvious answer is wrong.
- Refusals and safety. Requests the app must decline, and requests that look risky but are fine.
- Multi-step or ambiguous inputs. Cases where the app should ask a clarifying question.
Give experts a short writing guide. Ask for a mix of difficulties, ask them to vary phrasing, and ask them to write in the way customers write, not the way policy documents read. Otherwise you get tidy, formal inputs that are easier than real traffic.
A warning about expert cases: experts tend to write cases they already know the app handles, or cases that reflect their own idea of a typical user. Compare their cases against the log sample to check the distribution is not far from reality.
Synthetic cases
Synthetic generation is covered in depth in a later chapter, so only the essentials appear here. There are three common methods:
- Templates. Fill slots in a sentence, such as
"Can I return a {product} after {days} days?". This gives precise control and works well for boundary testing. - LLM generation. Ask a model to write inputs for a given slice, such as "angry customers asking about refunds".
- Mutation. Take an existing case and change it: add typos, translate it, make it longer, or insert a misleading detail.
Synthetic cases are useful when real examples are rare, for instance prompt-injection attempts. Their risks are sameness and unreality. Check a sample by hand, and never let synthetic cases outnumber real ones without recording the fact.
Record provenance on every case
The schema from earlier chapters includes a source field. This is where it pays off. When you see a low score, the first question is often "is this a real problem or an artifact of how we built the data?" Provenance answers it.
A useful source value is a small controlled vocabulary, such as production_log, expert, synthetic_template, synthetic_llm, synthetic_mutation, and public_benchmark. Add extra fields when they help, such as the sampling method or the id of the case a mutation came from.
{"id": "refund-214", "input": "can i return my laptop?? it came 2 wks late", "reference": null, "tags": ["returns", "late_delivery"], "source": "production_log", "sampling": "thumbs_down", "difficulty": "medium"}Here the reference is null because the case is waiting for labeling.
With provenance recorded, you can report accuracy by source in the same way you report it by tag. This function reuses the idea from the grading code in this tutorial.
from collections import defaultdict
def accuracy_by_source(cases, results):
# results maps case id to True or False
by_source = defaultdict(list)
for c in cases:
by_source[c["source"]].append(results[c["id"]])
return {s: sum(v) / len(v) for s, v in by_source.items()}If the score is 0.95 on synthetic cases and 0.70 on production cases, the synthetic set is too easy, and the overall number is misleading.
Common mistakes
- Using only the easy source. Teams often start with synthetic data because it is fast and never revisit it. The dataset then drifts from real use.
- Training on the test data. If you include test cases in prompts, few-shot examples, or fine-tuning data, scores become inflated. The split chapter covers how to prevent this.
- Copying model output as the reference. This makes the app look correct by definition.
- Forgetting the long tail. A random log sample under-represents rare inputs. Add targeted cases for them.
- Losing the origin. A case without a
sourcecannot be audited. - Ignoring time. Logs from last year may not match today's product. Record a date or collection window.
A practical mix to start with
There is no universal ratio, but a reasonable starting point for a first dataset is mostly real traffic with a layer of expert cases on top, and synthetic cases only where a slice is thin. For example, for 200 cases you might take roughly 100 from a random log sample, 40 from targeted log sampling (failures and escalations), 40 expert-written boundary and policy cases, and 20 synthetic cases for rare adversarial inputs. Treat these numbers as a starting point to adjust, not a rule. What matters is that you know the mix, because it is recorded in source.
Exercise
Your dataset has 300 cases: 250 synthetic, 30 expert-written, 20 from production logs. The app scores 94% overall, but users complain about quality. Name two likely causes related to where the cases came from, and one check you could run with the source field.
Show answer
Likely causes: (1) The synthetic cases dominate the dataset and are probably more uniform and easier than real traffic, so the overall score is inflated. (2) Only 20 production cases means real phrasing, typos, and unexpected requests are barely tested. A check: compute accuracy by source with a function like accuracy_by_source. If production-log accuracy is much lower than synthetic accuracy, the synthetic cases are too easy and the dataset needs more real cases.
Exercise
A teammate pulls 500 cases from the most recent 500 rows of the logs and writes the app's own answers into reference. Give two problems with this approach and a fix for each.
Show answer
Problem 1: the most recent rows may be dominated by one day, one incident, or one customer, so the sample is biased. Fix: take a random or stratified sample across a longer window. Problem 2: using the app's own output as the reference means the app will score as correct by construction, and any existing mistakes become the "right" answer. Fix: leave the reference empty and have a person or documented rubric supply it during labeling.