Building eval datasets
Create a labelled test set from real and synthetic examples covering edge cases.
By Invicly Tech, , in AI Engineering with Python. About 12 minutes to read.
In short
An eval dataset is a set of inputs with expected outputs or grading notes that you run your app against. It turns whether it seems better into a measurable score.
Explained simply
An eval dataset is an exam for your app. It is a list of inputs, each with a note on what a good answer looks like. You run the app on every input, score the answers, and get a number. Change a prompt, run the exam again, and compare the numbers. Now better or worse is a fact, not a feeling.
The best test cases come from real users: chat logs, support tickets, questions colleagues ask. Real inputs are messy. They have typos, missing details and two questions in one message. That mess is exactly what breaks AI apps, so your exam needs it.
Then add cases that are rare but important: tricky edge cases, questions the app must refuse, and attempts to misuse it. A model can help you write these, but a person should check every one.
Every case needs a label: the expected answer, or a short list of what a good answer must and must not do. Keep the whole set in Git with a version number, so scores from different weeks can be compared honestly.
Press Play on a diagram to walk through it one step at a time.
- 1Collect real inputs
Logs, support tickets, user questions
- 2Add edge cases
Synthetic tricky, ambiguous and adversarial inputs
- 3Label expectations
Expected answer or grading criteria
- 4Version it
Store in Git with a changelog
- 5Grow from failures
Add every production bug as a case
- Common questions
- About half the set
- From real logs
- Messy real inputs
- Typos and slang
- Two questions in one
- Vague wording
- Edge cases
- Very long or empty input
- Other languages
- Boundary values
- Should refuse or ask
- Out of scope
- Missing key detail
- Not in the docs
- Adversarial
- Prompt injection
- Requests for private data
In depth
What a good test case contains
A test case needs more than a question. Give it a stable ID so you can track it over time. Store the input exactly as the app receives it, including chat history or attached data when that matters. Then store the expectation, which comes in two styles.
Reference-based cases have a golden answer to compare against, which works well for short facts like a date or a price. Criteria-based cases list what a good answer must and must not do, such as mentions the 5 business day refund window and does not promise an exact date. Criteria work better for open-ended answers, where many wordings are correct.
For RAG apps, also store which documents should be retrieved, so retrieval can be scored on its own. Finally add tags such as topic, difficulty and origin (real or synthetic), so you can see scores per slice instead of one blended number.
- id, input, expected or criteria
- Expected sources for RAG cases
- Tags: topic, difficulty, real or synthetic
- Optional notes explaining tricky labels
Collecting real examples without leaking data
Do not just take the first 50 questions from the logs. They will mostly be the same few common questions. Group logged questions by topic, then sample a few from each group so rare topics are represented too. Remove near-duplicates, because ten copies of the same question make one behaviour count ten times.
Scrub personal data before a case goes into your repository: names, emails, phone numbers, account and order numbers. Replace them with realistic fake values so the case still makes sense. Check that your privacy policy allows using logs this way.
No users yet? Ask domain experts and colleagues to write questions without looking at the documents first, so they phrase them the way real users would. Run a short beta, collect what testers ask, and promote the best examples into the dataset.
Generating synthetic edge cases systematically
Asking a model to write 50 test questions gives you 50 similar, polite, easy questions. A better method is to define dimensions first. For a support bot these might be persona (new user, expert, angry customer), topic (billing, login, data export) and kind (simple, two questions in one, missing a key detail, out of scope). Combine them into tuples, then ask a model to write one realistic message for each tuple.
This gives coverage you control: 3 personas times 3 topics times 4 kinds is 36 distinct cases. Add adversarial cases by hand: prompt injection attempts, requests in another language, extremely long inputs and empty ones.
Review every generated case. Delete ones that no real user would write, fix unrealistic wording, and tag them as synthetic so you can compare scores on real versus generated inputs.
- 1Pick dimensions
Persona, topic, kind of request
- 2Combine tuples
Every mix, or a sampled subset
- 3Generate inputs
One realistic message per tuple
- 4Human review
Drop or fix unrealistic ones
- 5Label and tag
Expected behaviour, tag synthetic
Labelling: guidelines and agreement
Labels are only useful if two people would write the same one. Before labelling, write short guidelines: what counts as a correct answer, when the app should refuse, when it should ask a clarifying question, and how strict to be about wording.
Then test the guidelines. Have two people label the same 20 cases independently and compare. Where they disagree, the guideline is usually unclear, so fix it rather than just picking a winner. A domain expert, such as the support lead or a lawyer, should have the final word on facts.
Remember that the right behaviour is not always an answer. For out-of-scope or unanswerable questions, the label is the behaviour you want: politely declines, or asks which account the user means. Those cases catch the confident, invented answers that hurt trust most.
Versioning, size and splits
Store cases as JSONL (one JSON object per line) in Git next to your code. Give the dataset a version and record that version with every score you publish, because a score on v3 cannot be compared with a score on v2. Never silently edit a case; if a label was wrong, fix it in a commit with a clear message, or retire the case and add a new ID.
Start with 20 to 50 cases. Know the limit: with 50 cases, one case is worth 2 percentage points, so small differences are noise. Grow toward a few hundred as the app matures.
Keep a dev set you look at and tune against every day, and a held-out test set you run rarely. If you tune prompts on the same cases you report, your score will look better than real-world quality.
- JSONL in Git, version recorded with every score
- 50 cases: each case moves the score 2 points
- Dev set for tuning, held-out set for reporting
- Every production bug becomes a new case
Learn it in 4 short steps
About 45m each. Track them with a timer in your plan.
- 1Collect real user examples~45m
- 2Generate synthetic edge cases~45m
- 3Label expected outputs~45m
- 4Version the dataset~45m
Key points
- Start small: 20 to 50 well-chosen cases beat 1,000 random ones.
- Real user inputs reveal problems synthetic data misses.
- Include cases where the right answer is to refuse or ask a question.
- Never tune prompts on the same cases you report scores on.
Key terms
Tap a card to flip it. 0/5 known
Examples
{"id": "refund-01", "input": "How long do refunds take?", "expected": "5 business days", "tags": ["faq"]}
{"id": "refund-02", "input": "refund??? order 991", "expected": "Asks for email to verify", "tags": ["messy"]}
{"id": "oos-01", "input": "What is the CEO's salary?", "expected": "Politely declines", "tags": ["refusal"]}JSONL eval cases with expectations and tags.
Turning a month of logs into 40 test cases
Your support bot logged 2,000 questions last month. Step 1: export them and tag each with a topic, using simple keywords or a cheap model. Step 2: drop exact and near duplicates. Step 3: take a stratified sample: up to 5 per topic, with a fixed random seed so the sample is reproducible. Step 4: scrub names, emails and order numbers, replacing them with fake values. Step 5: sit with the support lead and label each case with expected behaviour. Step 6: commit as evals/support-v1.jsonl with a changelog line.
import random
from collections import defaultdict
def stratified_sample(rows: list[dict], per_tag: int = 5, seed: int = 42) -> list[dict]:
rng = random.Random(seed)
by_tag = defaultdict(list)
for r in rows:
by_tag[r["tag"]].append(r)
sample = []
for tag in sorted(by_tag):
items = by_tag[tag]
sample += rng.sample(items, min(per_tag, len(items)))
return sampleGenerating 36 synthetic cases from dimensions
You want coverage of personas, topics and request types you rarely see in logs. Step 1: list the values for each dimension. Step 2: itertools.product gives every combination, 3 times 3 times 4 = 36. Step 3: for each combination, ask a model to write one realistic message (the generate function is your own model call). Step 4: save each one with its dimensions as tags and an empty expected field. Step 5: a person reviews every case, deletes the unrealistic ones and writes the expected behaviour.
import itertools, json
personas = ["new customer", "power user", "frustrated customer"]
topics = ["billing", "login", "data export"]
kinds = ["simple question", "two questions in one", "missing key detail", "out of scope"]
PROMPT = "Write one realistic support message from a {p} about {t}. Make it a {k}. Return only the message."
with open("evals/synthetic-draft.jsonl", "w") as f:
for i, (p, t, k) in enumerate(itertools.product(personas, topics, kinds)):
case = {"id": f"syn-{i:03d}", "input": generate(PROMPT.format(p=p, t=t, k=k)),
"expected": "", "tags": [p, t, k, "synthetic"]}
f.write(json.dumps(case) + "\n")Quick reference
- Each case: stable id, exact input, expected answer or criteria, tags
- Sample logs by topic, not just the first N rows; remove near-duplicates
- Scrub names, emails and account numbers before committing cases
- Generate synthetic cases from dimensions (persona x topic x kind), then review by hand
- Label refusals and clarifying questions as expected behaviour
- Store as JSONL in Git and record the dataset version with every score
- With n cases, one case is worth 100/n percentage points
- Tune on a dev set; report on a held-out set
Common mistakes
- Only testing easy, clean inputs.
- Changing the dataset silently, making scores incomparable over time.
Quick quiz
Pick an answer to see if you're right and why.
Practice exercises
Try each one yourself first. Use the hint if you get stuck, then compare with the solution.
- Exercise 1easy
Write a script that loads a JSONL eval file and checks every case has a unique id, a non-empty input and at least one tag.
- Exercise 2medium
Write a scrubber that replaces emails and long digit runs (like order or phone numbers) in a case's input with placeholder values.
- Exercise 3hard
Split an eval set into dev and test so that each tag keeps roughly the same share in both (70/30), using a fixed seed, and write them to two files.
Check yourself
Answer in your head, reveal, then be honest with yourself.
Feel confident about this topic?
Frequently asked questions
- How many examples does an LLM eval set need?
- Start with 20 to 50 carefully chosen cases; that is enough to catch big regressions. Grow to a few hundred when you need to detect smaller differences.
- Can I use only synthetic data for evals?
- It is a fine start before launch, but real user inputs reveal problems synthetic data misses. Replace and extend with real cases as soon as you have them.
- What format should eval datasets use?
- JSONL is the common choice: one JSON object per line, easy to diff in Git, stream and append to.
- Should eval cases have exact expected answers?
- Only for short factual outputs. For open-ended answers, write criteria that a good answer must meet and must avoid.