Key takeaways
- ✓A random test set copies the traffic mix, so a group that is 1% of traffic gets about 1% of the cases. In 1,000 simulated random sets of 100, 345 had no critical case at all, and only 26% showed even one critical failure, although 3 in 10 critical requests fail.
- ✓Getting enough of a rare group by chance is wasteful: at least 20 critical cases, 19 times in 20, takes 2,784 random cases, 2,756 of them not critical. Stratified sampling takes the 20 directly: split requests into groups first, then draw from each group separately.
- ✓Where the cases go matters more than how many. The same 150 cases measure the critical group with a 95% interval 79 points wide when drawn at random (typically one critical case), 37 points with a floor of 20 per group (90/20/20/20), and 19 points with most cases on critical (20/20/20/90).
- ✓A test set that over-represents rare groups needs a weighted score: each group's pass rate times its share of real traffic. One evaluation scored 90.7% raw and 95.4% weighted against a true 94.55%. Over 2,000 simulated evaluations the raw score was 5.5 points low on average; the weighted one was right on average (+0.1).
- ✓Zero failures prove less than they seem: 20 of 20 clean leaves the failure rate possibly as high as 13.9% (about 3 ÷ n, the rule of three). Claiming “fails under 1%” takes 299 cases that all pass, so size a group's floor from the claim it must support.
- ✓Count harm, not just failures: normal requests cause two in three failures (36 of 54.5 per 1,000), but with a critical failure counted as 50× worse (a judgment call), 1% of traffic causes 69% of the harm.
- ✓Report the weighted overall score and every group on its own line with its interval. Here the critical interval, 53–89%, is entirely below a 90% bar: the release fails although the overall score looks great.
A support assistant passes 94.5% of its requests. That looks great. But 1 request in 100 is critical (a refund, private data, a safety question), and 3 in 10 of those fail. A random test set of 100 cases usually misses every one of those failures. This chapter is about which cases to test: how a random test set hides a rare group, how sampling each group separately fixes it, how to keep the overall score honest afterwards, and what to report.
The examples come from Lab 04 (Why Random Sampling Isn't Enough) of the AI evaluation labs. Its four scripts: 01_zero_catastrophe.py (how often a random test set misses the rare group), 02_stratified_designs.py (ways to split a fixed number of cases across groups, and what zero failures prove), 03_reweighting.py (raw against weighted scores, and a verdict per group) and 04_risk_based.py (where the harm is). Everything here is a simulation: the lab builds 100,000 support requests whose true results are fixed in advance, so every estimate can be checked against the truth. No real assistant was tested, and the failure costs are the lab's judgment call. The chapter leaves out the last part of Script 4, which plans a real test set for Lab 01's example store (it needs that lab's data), and covers effective sample size, the other ways to split cases and the weighted score's margin only briefly.
The simulated traffic
A test case is one request with a known right answer; the assistant's reply passes or fails. The score is the share that pass. The lab sorts requests into four groups (statisticians say strata, one stratum):
| Group | Share of traffic | True pass rate | Cost of one failure |
|---|---|---|---|
| normal | 90% | 96% | ×1 |
| difficult | 5% | 85% | ×2 |
| ambiguous | 4% | 80% | ×2 |
| critical | 1% | 70% | ×50 |
| overall | 94.55% |
The critical group is a hidden problem: 300 of its 1,000 requests fail, and the overall score, 94,550 of 100,000, still looks excellent. (The video rounds it to 94.5%.) The cost column says how much worse one failure is than a clumsy answer to a normal request; we'll need it at the end.
The hidden 1%
Think of a fire inspector who checks 100 random rooms in a big hotel. She sees bedroom after bedroom, and she may never open the kitchen, the room most likely to catch fire. A random test set works the same way: it copies the traffic mix, so a group that's 1% of traffic gets about 1% of the cases.
A fire inspector opens 100 random rooms of a hotel. Here each “room” is a test case drawn at random from 100,000 simulated support requests, coloured by its group. Critical requests are the kitchen: 1 in 100, and 3 in 10 of them fail. These are the first six random sets the lab's script drew, in order (not picked).
One critical case, and it failed. One case can't tell you how often that happens.
Critical cases in each of 1,000 random 100-case sets (highlighted: the set above)
345 of 1,000 sets (34.5%) had no critical case; the formula 0.99100 says 36.6%. Only 26% showed even one critical failure.
A bigger random set?
“Typical” is the median over 1,000 random sets of that size; the interval is the critical group's 95% Wilson interval, median width in percentage points. Even at 2,000 random cases it's 37 points wide. To get at least 20 critical cases 19 times in 20 by chance takes 2,784 random cases, 2,756 of them not critical. Or take 20 critical cases directly.
The lab drew 1,000 random test sets of 100 cases each (Script 1):
- 345 of 1,000 had no critical case at all (34.5%; the formula 0.99¹⁰⁰ says 36.6%). Most of the rest had one or two.
- Only 26% showed even one critical failure, although 3 in 10 critical requests fail.
- The overall score was right on average (94.7% against the true 94.55%). Nothing in it warns you.
A bigger random set helps slowly. At 2,000 random cases the typical set has 20 critical cases, and the critical group's confidence interval (the range its true pass rate is likely in, here at 95%; Chapter 1 covers them) is still 37 percentage points wide. The lab measures all intervals here with the Wilson interval, the one Chapter 1 recommends for pass rates; "points" means percentage points throughout. To be fairly sure of getting 20 critical cases (19 times in 20) by chance takes 2,784 random cases, 2,756 of them not critical. Or you could take 20 critical cases directly.
Sample each group
A good inspector always checks the kitchen. For tests, split the requests into their groups first, then draw cases from each group separately. That's stratified sampling. Usually you also give every group a minimum number of cases, a floor, so each one can be measured at all.
Script 2 splits the same 150 cases six ways and runs each design 2,000 times. Plans are written normal / difficult / ambiguous / critical, so 90/20/20/20 means 90 normal cases and 20 of each other group:
| Design | How it splits 150 | Critical interval width (median) | Overall score SD | Worth (effective n) |
|---|---|---|---|---|
| Random | by chance (critical: typically 1, none in 22.7% of sets) | 79 points | 1.84 points | 150 |
| Proportional to traffic | 135 / 8 / 6 / 1 | 79 | 1.82 | 150 |
| Neyman | 124 / 12 / 11 / 3 | 73 | 1.83 | 145 |
| Floor of 20 | 90 / 20 / 20 / 20 | 37 | 1.93 | 109 |
| Equal | 38 / 38 / 37 / 37 | 28 | 2.96 | 47 |
| Risk-based, floor of 20 | 20 / 20 / 20 / 90 | 19 | 3.92 | 25 |
What the columns mean:
- Critical interval width: how precisely the design measures the critical group. With 150 random cases you typically get one critical case, and one pass in one gives a Wilson interval from 21% to 100%: 79 points wide, so the true rate could be almost anything. Twenty critical cases (14 passing, at the true 70%) give 48–85%, 37 points. Ninety (63 passing) give 60–78%, 19 points.
- Overall score SD: how much the overall score (weighted back to real traffic, as in the next section) moved from one evaluation to the next. The standard deviation (SD) is the typical distance from the average.
- Effective n: how many equally weighted cases the design is worth for the overall score (Kish's effective sample size, Script 3). Oversampled cases get small weights, so 150 risk-based cases are worth about 25 for the overall number. Neyman's 145 was computed with the lab's code; the script doesn't print it.
Neyman allocation gives each group cases in proportion to its traffic share times how much its results vary (√(p(1−p)), largest for pass rates near 50%); it gives the most precise overall score for the budget. Risk-based gives cases in proportion to traffic share × failure rate × cost of one failure.
No design wins everywhere. Random, proportional and Neyman tie on the overall number (SD about 1.8 points), because the groups' pass rates are close, and all three leave the critical group unmeasured. A floor of 20 gives up about 0.1 point of overall SD and halves the critical interval. Equal and risk-based pay more overall precision for the best critical measurement. Same 150 cases; only where they go has changed.
at least 20 per group; normal gets the rest.
The 150 cases, by group
normal 90 · difficult 20 · ambiguous 20 · critical 20
A typical critical result, at the true 70%, and its 95% interval
14 of 20 passed → 48% to 85%, 37 points wide
Critical interval: the median width over 2,000 simulated evaluations (the bar above is one typical result). Overall score SD: how much the overall score (weighted back to traffic) moved between evaluations. Effective n: how many equally weighted cases the design is worth for the overall score (Kish).
All clean: what can zero failures prove?
95% upper bound = 1 − 0.05^(1/20). Not enough to claim "fails under 1%": that takes 299 clean cases.
Raw or weighted score?
There's a catch. A 90/20/20/20 test set is heavy on the rare groups on purpose: they are 40% of the test set and 10% of real traffic. So there are two ways to score it. Here is one evaluation (Script 3, Exercise 1):
| Group | Passed | Rate | Share of the test set | Share of real traffic |
|---|---|---|---|---|
| normal | 87 / 90 | 96.7% | 60% | 90% |
| difficult | 17 / 20 | 85% | 13.3% | 5% |
| ambiguous | 17 / 20 | 85% | 13.3% | 4% |
| critical | 15 / 20 | 75% | 13.3% | 1% |
- The raw score counts every case the same: 136 of 150, 90.7%.
- The weighted score counts each group by its share of real traffic: 0.90 × 96.7% + 0.05 × 85% + 0.04 × 85% + 0.01 × 75% = 95.4%. Critical cases are 13% of the test set but count for 1%.
The truth is 94.55%. The weighted score is off by less than a point, which is chance. The raw score is off by about four, and not by chance: it's low because the test set is full of hard cases. It describes the test set, not the traffic. Over 2,000 such evaluations (Exercise 2), the raw score averaged 89.0%, 5.5 points low on average and below the truth in 98.9% of them; the weighted score averaged 94.6%, +0.1 points, right on average.
So report the weighted score for the whole system, and every group's own score next to it.
What zero failures prove
Suppose you fix the assistant and all 20 critical cases pass. Zero failures. Is it safe? Not yet. With 0 failures in n cases, the true failure rate could still be as high as 1 − 0.05^(1/n) at 95% confidence:
| Clean cases (0 failures) | Failure rate could still be up to | Rule of three: 3 ÷ n |
|---|---|---|
| 10 | 25.9% | 30% |
| 20 | 13.9% | 15% |
| 50 | 5.8% | 6% |
| 100 | 3.0% | 3% |
| 300 | 1.0% | 1% |
The rule of three is the shortcut: up to about 3 ÷ the number of cases. Turned around, it tells you how many clean cases a claim needs: "fails under 10%" takes 29, "under 5%" 59, "under 1%" 299, "under 0.1%" 2,995, and every one must pass; a single failure means you need more. So size a group's floor from the claim it has to support, not from a round number.
Where the harm is
Which group deserves the extra cases? Count the failures per 1,000 requests: 1,000 × traffic share × failure rate (Script 4, Exercise 1).
| Group | Failures per 1,000 | Cost of one failure | Harm per 1,000 | Share of harm |
|---|---|---|---|---|
| normal | 36 | ×1 | 36 | 17% |
| difficult | 7.5 | ×2 | 15 | 7% |
| ambiguous | 8 | ×2 | 16 | 7% |
| critical | 3 | ×50 | 150 | 69% |
| total | 54.5 | 217 |
Normal requests cause two in three failures. But failures don't all cost the same: a wrong refund or a data leak is far worse than a clumsy answer. With a critical failure counted as 50 times worse, 1% of traffic causes 69% of the harm. That ×50 is a judgment call: agree it with whoever owns the risk (support leads, legal, safety), and write it down, because it decides where the test budget goes. A pass rate counts every failure the same and points you at the wrong group. This is risk-based testing, borrowed from QA: test where a failure is both likely and expensive.
The same script also estimates harm from 150-case test sets: with proportional allocation (one critical case) the estimate swung from 27 to 598 harm units (the middle 95% of 2,000 runs); any design that gives critical a real share was about 5× steadier (SD 45–55 against 232). Most of that gain came from the floor, not from fine-tuning the split.
What to report
For the evaluation above: first the score for the whole system, weighted back to real traffic. Then every group on its own line, with its interval, against its own bar. Script 3 sets bars per group (normal 95%, difficult 80%, ambiguous 75%, critical 90%) and reads each line the same way: a group meets its bar if the whole interval is above it, fails if the whole interval is below, and otherwise you can't tell yet.
One 90/20/20/20 test set (90 normal, 20 of each other group), run once. Rare groups are 40% of the test set but 10% of real traffic. Two ways to score it:
| group | passed | rate | counts for |
|---|---|---|---|
| normal | 87/90 | 96.7% | 60.0% (90 of 150) |
| difficult | 17/20 | 85.0% | 13.3% (20 of 150) |
| ambiguous | 17/20 | 85.0% | 13.3% (20 of 150) |
| critical | 15/20 | 75.0% | 13.3% (20 of 150) |
136 of 150 passed. The raw score describes this test set, which is full of hard cases, not real traffic. Over 2,000 such evaluations it averaged 89.0%: 5.5 points low on average, and below the truth in 98.9% of them.
Every group with its 95% interval, against its target
Red tick: the group's target (the lab's Script 3 targets). A group meets it if its whole interval is above, fails if all of it is below, and otherwise we can't tell. The critical interval, 53–89%, sits entirely below 90%: the release fails, though the weighted score is 95.4%.
Where the harm is, per 1,000 requests
Failures per 1,000 requests = 1,000 × traffic share × failure rate: 36 + 7.5 + 8 + 3 = 54.5. Normal requests cause two in three of them.
The critical line is the one that matters: 15 of 20, interval 53–89%, all of it below 90%. The release fails, although the overall score is 95.4%. Twenty cases were enough to fail it because 70% is far from 90%; the other three groups sit close to their bars and stay "can't tell". Script 3's own release table runs the same check on a fresh draw (critical: 13 of 20, 43–82%) and reaches the same verdicts; it estimates that deciding the close groups would take roughly 50 to 1,600 cases each, more the closer a group sits to its bar. Spend extra cases where the decision is close and the stakes are high.
What to do
- Name your groups before you sample: by topic, intent, account type, or a classifier. Find the rare ones where a failure is expensive.
- Sample each group separately, with a floor so every group is measurable. Put extra cases where failures are likely and costly.
- Size the floor from the claim. "Fails under X%" with zero failures needs about 3 ÷ X clean cases (299 for 1%).
- Weight the overall score back to real traffic. Never report the raw score of an oversampled test set as "the score".
- Report every group on its own line with its interval, and decide per group: meets, fails, or can't tell.
- Write down the failure costs with whoever owns the risk, and revisit them after incidents.
Caveats
- It's a simulation. The traffic, the groups and their true pass rates are made up so the truth is known exactly. Real groups won't be this clean, and the numbers here are illustrations of the method, not facts about any assistant.
- The groups must be labelled correctly. Stratified sampling assumes you know which requests are critical before you sample. If some critical requests are filed as normal, the critical estimate and the weights are both off. The lab leaves that as an exercise.
- The weighted score's margin is a bit optimistic. Its 95% margin (half the interval's width; Chapter 1) contained the truth in 90% of the 2,000 evaluations, not 95%, because it uses the simple normal-approximation formula inside each group, and that formula undercovers for a group near 100% (normal: 96% on 90 cases), as Chapter 1 showed. Resampling within each group (a stratified bootstrap) is the better interval.
- Weighting costs overall precision. A design that measures critical well is worth fewer cases for the overall number (risk-based 150: about 25). Teams often run both: a small proportional set for the headline score, and a stratified set for the release decision.
- The costs are a judgment call. Change ×50 and the share of harm changes with it (the widget's slider shows how much).
- Rounded in the lab's printout. Script 1 prints the 34.5% of random sets with no critical case as "34%"; this chapter uses the exact share.
The checklist
- Why can a random test set give a good overall score and still miss the problem that matters?
- What is stratified sampling, and what is a floor for?
- How do the main ways to split cases (proportional, Neyman, equal, risk-based) differ, and when would you use each?
- Why does an oversampled test set need a weighted score, and what do you report?
- What can you conclude from zero failures in n cases?
- Why count harm, not just failures, when deciding where cases go?
Practice: score a stratified test set
Write Lab 04's math: the chance a random test set misses a rare group, how many random cases it takes to get 20 of them, the Wilson interval, raw and weighted scores, what zero failures prove, a verdict per group, and harm per 1,000 requests. The tests use the lab's recorded numbers: 36.6% with no critical case, 2,784 random cases, the 79 / 37 / 19-point critical intervals, 90.7% raw against 95.4% weighted, 13.9% and 299, the critical group failing at 53–89%, and 69% of the harm.
Quiz
1.1 request in 100 is critical. How often does a random test set of 100 cases contain no critical case at all?
2.You have 150 test cases. Which split measures the critical group most precisely?
3.One test set with 90 normal cases and 20 from each rarer group passed 136 of 150: 90.7%. Real traffic is 90 / 5 / 4 / 1%. Which number do you report as the overall score?
4.After a fix, all 20 critical test cases pass. What can you claim?
5.Normal requests cause 36 of 54.5 failures per 1,000; critical ones cause 3. A critical failure costs 50× a normal one. Where do extra test cases pay off most?
6.The weighted overall score is 95.4%. The critical group scored 15 of 20, with a 95% interval of 53–89%, and its bar is 90%. What's the release verdict?
Check your understanding
Try each question before opening its answer.
Why can a random test set give a good overall score and still miss the problem that matters?
It copies the traffic mix, so a group that's 1% of traffic gets about 1% of the cases. In the lab, 345 of 1,000 random 100-case sets had no critical case at all, and only 26% showed even one critical failure, while the overall score was right on average (94.7% against 94.55%). The average is dominated by common, easy requests.
What is stratified sampling, and what is a floor for?
Split the requests into groups first, then draw test cases from each group separately. A floor is a minimum number of cases per group, so every group can be measured at all. With 150 cases, a floor of 20 (90/20/20/20) shrank the critical group's interval from 79 points (random) to 37.
How do proportional, Neyman, equal and risk-based splits differ, and when would you use each?
Proportional follows traffic: an unbiased overall score with no weighting, but rare groups get almost nothing. Neyman adds more cases where results vary more: the most precise overall score, though here it barely beat proportional because the pass rates are close. Equal gives each group the same number: best for comparing groups. Risk-based follows traffic × failure rate × cost: best for measuring harm. Add a floor to any of them; most of the practical gain came from the floor.
A test set with 90 normal cases and 20 from each rarer group scored 90.7% raw and 95.4% weighted. Which do you report, and why?
The weighted score: each group's rate times its share of real traffic. The test set is 40% rare, harder groups against 10% of traffic, so the raw score describes the test set. Over 2,000 simulated evaluations, raw was 5.5 points low on average and below the truth 98.9% of the time; weighted was right on average. Report it with every group's own rate and interval.
All 20 critical cases pass. What can you claim, and how many clean cases would “fails under 1%” take?
Only that the failure rate is probably under 13.9% (1 − 0.05^(1/20)), about 3 ÷ 20 by the rule of three. “Under 1%” takes 299 cases, all passing. Size the floor from the claim the group has to support.
Normal requests cause most failures. Why do extra cases go to critical ones?
Because harm, not the failure count, is what matters: traffic share × failure rate × cost of one failure. With a critical failure counted as 50× worse (a judgment call agreed with whoever owns the risk), critical requests cause 150 of 217 harm units per 1,000 requests, 69%, from 1% of traffic.
The weighted score is 95.4%, and the critical group's interval is 53–89% against a 90% bar. Ship it?
No. A group fails when its whole interval is below its bar, and 89% is below 90%. The overall score can't show it: the critical group counts for 1% of it. That's why every group gets its own line in the report.
Next up: Chapter 4, saturation: this chapter sized test sets to measure how often each group fails. The next one asks how many cases it takes to find the different ways an AI fails (its failure modes), and why that takes far more.