Lesson 6.2: Building a test set
Build an eval test set that reflects real use: where cases come from, how to cover slices, how many you need, labelling quality and keeping a held-out set.
An eval is only as good as the cases it runs on. A set made of twenty tidy questions that the team wrote on a Friday will tell you the system is excellent, and the first week of real traffic will show otherwise. A set that is large but copied from one source will be blind to everything outside it. A set whose answers were labelled carelessly will mark good answers wrong and poor ones right, and you will chase phantom problems. Building the test set is therefore the most valuable and least glamorous part of evaluation. It is the place where you write down, in concrete examples, what your product is supposed to do. This lesson shows where cases come from, how to cover the variety of real use, how to write down what a good answer is, how many cases you need, how to check that your labels can be trusted and how to keep part of the set hidden from your own tuning. By the end you will be able to gather cases from logs, experts, synthetic generation and past failures, plan coverage across slices and weight the results back to real traffic, write a case that includes input, expected result and metadata, size a set for the decisions it must support, measure how well two labellers agree and correct for chance, split a set into a development part and a held-out part, and keep the set fresh and private. You should have read Lesson 6.1. No programming is needed, and the arithmetic is percentages and weighted averages.
What a test set is for
A test set answers a question that you ask over and over: is this version of the system good enough, and is it better or worse than the last one? To answer it you need cases that stand in for the real world. If the cases are unlike real use, the answer is misleading however carefully you grade them. So the first design question is not "how many" but "representative of what".
Think of the people and situations that will use the feature, and ask what range of inputs they will send. A customer-support assistant will get short and long questions, polite and angry ones, questions in English, Hindi and a mix of both, questions that the documents answer, questions they only partly answer and questions that have nothing to do with the product. Each of these is a kind of case that the test set should contain, in a sensible proportion.
Where cases come from
Real traffic. The best source, when you have it. Sample from logs of actual questions, removing personal information first. Real inputs are messier and odder than anything a team invents.
People who will use it. Before launch there are no logs. Ask support staff, sales or operations people to write the questions they hear every day. A twenty-minute session with three practitioners can produce fifty cases that no engineer would think of.
Documents and data. Pick passages from your sources and write a question each one answers. This guarantees that an answer exists, and the passage is the reference.
Synthetic generation. Ask a model to write questions from documents or to produce variations of a real question: shorter, ruder, with typos, in another language. This is fast and good for coverage, but the questions tend to be tidier and more uniform than real ones, and a model may write questions that only it would ask. Always review them, and mix them with real ones.
Adversarial and edge cases. Write cases that try to break the system: questions that need a document that does not exist, requests for things the product must refuse, attempts to make it ignore its rules, inputs that are empty, very long or in an unexpected format.
Failures. Every bad answer that a user reports, and every failure you find in review, becomes a case. This is the most important source over time, because it makes the set a record of what has gone wrong.
Mix the sources. A good starter set might be half real or expert-written, a quarter synthetic and a quarter edge cases and past failures.
Cover the slices
Variety matters more than volume. Decide the slices that matter for your product and make sure each has enough cases. Typical slices are:
Topic or intent, such as refunds, shipping, account access and payments.
Difficulty, from simple lookups to questions needing several documents.
Language and style, including mixed-language text and spelling mistakes.
User type, such as new customer, business customer or staff.
Expected behaviour, including cases where the right response is to decline, to ask a clarifying question or to hand over to a person.
Length and format, such as one-line queries and pasted emails.
Make a small grid of the slices and count the cases in each cell. Empty cells are blind spots.
Predict first: real traffic for your assistant is 60% simple questions, 30% medium and 10% hard. You will build a set of 100 cases. Should you copy those proportions, or choose different ones? Think about how many hard cases you would have and what you could learn from them before you read on.
If you copy the proportions, you have only 10 hard cases. The pass rate on 10 cases is very uncertain. Take a true pass rate of 55% on hard questions: the margin of error from Lesson 6.1 is about 1.96 × the square root of 0.55 × 0.45 ÷ 10, which is 1.96 × 0.157 = 31 points. You would be guessing, and hard questions are where the problems are. With 30 hard cases the margin is about 18 points, with 50 about 14, and with 100 about 10.
The usual answer is to oversample the slices that are rare but important, so each slice has enough cases to judge. Then, when you report one overall figure, you weight each slice by how common it is in real traffic. Suppose you build the set as 40 simple, 30 medium and 30 hard cases, and the pass rates are 95%, 82% and 55%.
The plain average over the set is (0.40 × 95) + (0.30 × 82) + (0.30 × 55) = 38 + 24.6 + 16.5 = 79.1%.
Weighted by real traffic, 60%, 30% and 10%, it is (0.60 × 95) + (0.30 × 82) + (0.10 × 55) = 57 + 24.6 + 5.5 = 87.1%.
The two differ by eight points. The first describes your test set, which is deliberately hard. The second is the best estimate of what users experience. Report both, along with the slice figures, and be clear which is which. If you quote the plain average to a manager as "our quality", you will understate it, and if you do the opposite when you are being tested for a launch gate, you may overstate it.
What goes in a case
A case is more than a question. Each one should carry the following.
1. An identifier, so that you can talk about it and track it across versions.
2. The input, exactly as the system will receive it, including any conversation history, user details and context the system gets.
3. What a good result looks like. This can be a reference answer, a list of facts the answer must contain, a list of things it must not say, the passage that should be cited, or a description of the right behaviour such as "decline politely and offer a link to support".
4. Metadata, meaning the slice labels: topic, difficulty, language, source of the case, date added and who wrote it.
5. A note on why it matters, for cases drawn from failures. "Customer got wrong refund window for digital goods" is worth far more than a bare question.
A short example for a returns assistant:
Field · ValueID · ret-042
Input · "I downloaded an ebook by mistake, can I get my money back?"
Must contain · States that digital goods cannot be returned after download. Cites the digital-goods section.
Must not contain · The 30-day return window. A promise of a refund.
Slice · Refunds, medium, English, from a real ticket
Note · Version 4 prompt wrongly offered a refund.
Writing the "must not contain" line is a habit worth building. Many of the worst failures are things the system says that it should not, and a list of required facts alone will not catch them.
How many cases
There is no single number, but you can reason about it.
To get started, 30 real cases give a first baseline and catch large problems. The margin of error on a pass rate is about 14 points, so use it for gross checks only.
To compare versions, you need enough cases that the differences you care about stand out from noise. Use the margin formula from Lesson 6.1: to detect a difference of five points on pass rates near 80%, you need hundreds of cases.
For each slice you report, aim for at least 30 cases, and more for the slices that carry the most risk.
For rare, severe failures, such as a harmful reply, count how many cases you have in that category. If an event happens in one in a thousand requests, a set of 100 will usually not contain a single example, so you test it with purpose-built cases and watch it in production instead.
A practical path is to start at 30, grow to 100 in the first month and to a few hundred as the product matures, adding cases whenever a failure teaches you something. Quality beats quantity: 150 carefully labelled cases are worth more than 1,500 careless ones.
Can you trust the labels?
The reference answers and pass-fail judgments come from people, and people disagree. If two careful reviewers cannot agree on whether an answer is good, your eval is measuring noise in the labelling. Check this early.
Take 50 cases and have two reviewers grade each independently, as pass or fail. Suppose they agree on 41, so the observed agreement is 41 ÷ 50 = 82%. That sounds high, but some agreement happens by chance, especially if most answers pass. If reviewer A passes 70% of cases and reviewer B also passes 70%, then by chance alone they would both say pass in 0.7 × 0.7 = 49% of cases and both say fail in 0.3 × 0.3 = 9%, so they would agree 58% of the time without any shared judgment. Cohen's kappa corrects for this:
kappa = (observed agreement − chance agreement) ÷ (1 − chance agreement)
Here (0.82 − 0.58) ÷ (1 − 0.58) = 0.24 ÷ 0.42 = 0.57. A kappa near 1 means near-perfect agreement beyond chance, and a kappa near 0 means no better than chance. Values around 0.4 to 0.6 are usually called moderate, and above 0.8 strong. A kappa of 0.57 suggests that the guidelines are not clear enough, and you should read the cases where the reviewers disagreed, work out why and sharpen the criteria. Often the problem is a vague standard such as "complete answer" that each person reads differently.
Other habits that improve label quality are to write a short guideline with examples of pass and fail, to have domain experts decide the hard cases, to settle disagreements by discussion and record the reason, and to re-label a sample after a month to check that standards have not drifted.
Keep some cases hidden
If you tune your system until the test cases pass, the pass rate stops being a fair estimate of how it will do on new cases. You have fitted the system to the set. The remedy is to split the set into two parts.
A development set, which you look at, learn from and tune against.
A held-out set, which you do not look at while tuning, and use only for a final check before a release or for a periodic review.
A common split is about 70% and 30%. If the score on the development set is much higher than on the held-out set, you have over-fitted. The same applies to examples in your prompt: never put test cases in the prompt as few-shot examples, or remove them from the set. When the held-out set has been used many times, its value fades, so refresh it with new cases from live use.
Keeping the set healthy
Version it. Store the set in files under version control, with a log of what was added or removed, so that a score can be tied to the exact set that produced it.
Remove duplicates. Near-identical cases inflate one slice and give a false sense of coverage.
Protect privacy. Strip names, phone numbers, account numbers and other personal data from real examples before they enter the set, and restrict who can read it. India's data protection law and your own policies apply to test data too.
Review for staleness. Policies change, products are retired, and a case whose reference answer is out of date will mark correct answers wrong. Review the set every quarter, and when a document changes.
Add from failures. Make adding a case the last step of fixing any bug.
Keep an owner. Someone should be responsible for the quality and growth of the set.
Three worked examples
Example 1: starting from nothing. A start-up is building a tool that drafts replies to customer emails. It has no logs. A product manager and two support staff spend an afternoon writing 40 emails they have seen, covering complaints, delivery queries, refund requests, compliments and spam. A model generates 20 variations with typos and different tone, which they review and keep 15 of. They add 10 edge cases: an empty email, an email in Hindi written in English letters, and a threat. They write for each case what the reply must contain and must not promise. They have 65 cases, a baseline and a first sense of where the tool is weak, without any production data.
Example 2: reweighting. A bank's assistant has 100 test cases, split 40, 30, 30 by difficulty. Plain accuracy is 79%, and the team worries it is below the 85% target. After weighting by real traffic, 60%, 30% and 10%, the figure is 87%, which meets it. They report both, and say that the plain figure is a stress test and the weighted one is an estimate of the user experience. They also notice the hard slice at 55% and set a separate target for it.
Example 3: noisy labels. A team grades summaries as good or poor, and two reviewers agree on 82% of cases, with both passing about 70%. Kappa is 0.57. They look at the 9 disagreements and find that half involve whether a summary that omits a minor clause is "complete". They rewrite the rubric to say that a summary passes if it includes all parties, dates, amounts and obligations, and may omit minor definitions. A second round on 50 new cases gives agreement of 92%, with both reviewers passing 70%, and kappa rises to 0.81.
A test set worksheet
1. The users and situations. Who sends what?
2. The slices. Topic, difficulty, language, user type, expected behaviour.
3. The sources. Real logs, experts, documents, synthetic, edge cases, failures.
4. The grid. Cases per slice, and the empty cells.
5. The weights. Share of each slice in real traffic.
6. The case format. Fields, including must-contain and must-not-contain.
7. The size. Now, in a month, in a quarter, and the minimum per slice.
8. The labels. Who grades, by what guideline, and the kappa.
9. The split. Development and held-out sets.
10. The care. Versioning, privacy, review dates and owner.
Common mistakes
Using only questions the team wrote, which are cleaner than real ones.
No hard cases, so scores look good until launch.
Copying traffic proportions for a rare but important slice.
Quoting the plain average as the user experience, or the weighted one as a stress test.
Cases without a statement of what good means.
Never checking that two people agree.
Tuning on the whole set.
Real personal data in the set.
A set that is never updated.
Key takeaways
The test set is where you write down, in examples, what the product should do. It must represent real use, with variety and the right difficulty.
Draw cases from real traffic, practitioners, documents, synthetic generation, edge cases and, above all, past failures.
Plan slices and oversample rare but important ones so that each has enough cases. With 10 hard cases the margin of error is about 31 points, and with 50 about 14.
Report the plain average and the traffic-weighted average. In the example they are 79.1% and 87.1%.
A case has an input, a description of a good result including what it must not say, and metadata.
Check label quality with agreement corrected for chance. Observed agreement of 82% with both reviewers passing 70% gives kappa 0.57, which is moderate.
Keep a held-out set unseen during tuning, and keep the whole set versioned, private, reviewed and owned.
Check yourself
1. Why oversample hard cases?
Hard cases are a small share of traffic but carry much of the risk, and with too few of them the pass rate on that slice is too uncertain to be useful.
2. A set has 50 simple cases passing at 90% and 50 hard cases passing at 60%. Real traffic is 80% simple and 20% hard. What is the plain average, and the weighted average?
Plain: (90 + 60) ÷ 2 = 75%. Weighted: 0.8 × 90 + 0.2 × 60 = 72 + 12 = 84%.
3. Two reviewers agree on 90% of cases, and both pass 80%. Is that agreement high beyond chance?
Chance agreement is 0.8 × 0.8 + 0.2 × 0.2 = 0.68. Kappa is (0.90 − 0.68) ÷ (1 − 0.68) = 0.22 ÷ 0.32 = 0.69, which is fairly good but not strong.
4. Why should a case state what the answer must not contain?
Many serious failures are things the system says that it should not, and a list of required facts would not catch them.
5. Why keep a held-out set?
Tuning on every case makes the score optimistic. A set you have not looked at gives a fairer estimate of performance on new inputs.
6. What is the best single source of new cases over time?
Real failures, which make the set a record of what has gone wrong and prevent the same problem returning.
Try this
Build a small test set. Set aside 90 minutes.
1. Choose an AI task and list five slices that matter, such as topic, difficulty, language and expected behaviour.
2. Collect 30 cases: ask two or three people who know the task to write 10 each, and add 5 edge cases of your own.
3. For each case, write the input, what a good result must contain, what it must not contain and its slice.
4. Count cases per slice, and write which cells are empty or thin.
5. Have a second person grade the outputs of one system on 20 of the cases independently, and use the simulator to compute kappa.
6. Set aside a third of the cases as a held-out set that you will not look at while tuning.
7. Use the first simulator with your slice pass rates and traffic shares to find the plain and weighted scores.
A good result is a 30-case set with a written good-result field for each case, a slice grid with gaps marked, a kappa figure, a held-out split and both a plain and a weighted score.
Tags: AI Engineering Evaluation Test sets Data quality LLM applications