Trials per Case: Separating a Real Effect From Run-to-Run Variance When You Compare Two Prompts
One run says prompt B wins 16 to 14; a second run says prompt A wins 16 to 15. Running the same 20 cases five times on both prompts, pairing the differences and reading the spread first gives an honest answer: a gap of +0.14 against a spread of 0.05, separated.
What you will learn
- Show why one run of each prompt can name a different winner every time
- Compare two prompts on the same cases with several trials per case and paired differences
- Read the spread before the mean and call a result separated only when the gap clears a rule fixed before the run
- Plan a comparison inside a model-call budget and state the smallest gap that budget can separate
Before you start
- Building an eval set with code checks
- Basic statistics: mean and standard deviation
A support team has a new prompt for the shop agent. They run it once, and it beats the current one. The team lead says: ship it. But was that a real effect, or just how one run fell?
This article covers three habits that answer that question: trials per case, paired cases, and the spread before the mean.
One run each says one thing, then the other
SupportDesk has prompt A in production and a new prompt B. They run the same 20 cases on both. First run: A passes 14 of 20, B passes 16. B wins by two. Run it again: A passes 16, B passes 15. Now A wins by one.
Same prompts, same 20 cases, a different winner. One run each cannot say which is the real effect.
Timing two pairs of running shoes
Think of timing two pairs of running shoes. Both pairs run the same track: that is paired cases, both prompts on the same cases. Each runs several laps, because the wind changes every lap: that is trials per case. And you look at how much the laps vary before you look at the average: that is the spread before the mean. One lap each mostly tells you about the wind.
The version we are replacing
The project runs against a stand-in: the Anthropic SDK on an httpx mock transport with scripted replies that vary from call to call, so no API key is needed. Every number below comes from those scripted test values, not from any real model. Budgets are counted in model calls, never in money. Here is naive_compare.py:
def winner(a, b):
score_a = sum(r[0] for r in a.values())
score_b = sum(r[0] for r in b.values())
return score_a, score_b, "B" if score_b > score_a else "A"
Two single runs, one score each, and the higher one wins. No spread, no second run.
One prompt, run again, moves on its own
The pilot runs 20 cases, 5 trials, 2 prompts: 200 calls. Read the five runs of each prompt separately:
pilot: 20 cases x 5 trials x 2 prompts = 200 calls
one run each: A 14 of 20 B 16 of 20 -> B wins
one run each: A 16 of 20 B 15 of 20 -> A wins
same prompt, 5 runs, of 20
A 14 16 12 13 15 moved 4
B 16 15 18 18 17 moved 3
Across five runs, A moved by four cases and B by three. Neither prompt holds still, so a two-case win from one run is mostly wind. Where that run-to-run movement comes from on the model side is covered in temperature and top-p sampling.
The version that holds up
The team writes its rule down first, in rules.json, before seeing any result:
{
"trials": 5,
"min_delta": 0.05,
"spread_multiple": 2
}
Then experiment.py:
def passes(reply, checks):
return int(all(CHECKS[name](reply, arg)[0] for name, arg in checks))
def run_trials(ask, trials):
"""table[case id] = one 0 or 1 per trial"""
table = {c["id"]: [] for c in CASES}
for _ in range(trials):
for c in CASES:
reply = ask(c["text"])
table[c["id"]].append(passes(reply, c["checks"]))
return table
def paired(a, b, ids):
"""B's pass rate minus A's, per case"""
return [mean(b[i]) - mean(a[i]) for i in ids]
def compare(a, b, ids):
diffs = paired(a, b, ids)
delta = mean(diffs)
spread = stdev(diffs) / sqrt(len(diffs))
least = RULES["min_delta"]
wide = RULES["spread_multiple"] * spread
need = max(least, wide)
if abs(delta) < need:
return delta, spread, "not separated"
return delta, spread, "separated"
run_trialsruns every case more than once and keeps a 0 or 1 per trial.pairedtakes one difference per case: B's pass rate minus A's, on the same case. That removes the case-to-case difficulty from the comparison.- The spread is the standard deviation of those differences over the square root of the case count: how far the average gap could wander.
- The bar is the larger of 0.05 and twice the spread. Inside the bar, the answer is not separated.
The spread first, then the mean
paired, 20 cases x 5 trials
spread 0.05 delta +0.14 separated
paired, A against A (2 trials v 2)
spread 0.07 delta -0.12 not separated
Read the spread first: 0.05. Then the delta: +0.14, prompt B ahead. Twice the spread is about 0.11 (the lecture's figure; the printout rounds the spread), so the delta clears the bar: separated.
The second line is a control: prompt A against itself, two trials against two. The delta is -0.12, which looks like a real difference, yet the same prompt cannot beat itself. The spread is 0.07, so the bar is about 0.14 and the verdict is not separated. That is what run-to-run variance alone can produce.
What can you claim? On these 20 cases, B passed about 0.14 more often, outside the spread. With only 20 cases, you do not claim B wins on every kind of ticket. Report the gap, the spread and the number of cases, and stop there.
A winner declared from a few dozen calls
Now a watch-out. A team runs a small test: 12 cases, one trial, two prompts, 24 calls. Here is that same test repeated five times:
24 calls, run 5 times (12 cases x 1 trial)
spread 0.15 delta -0.08 not separated
spread 0.17 delta -0.17 not separated
spread 0.14 delta +0.33 separated
spread 0.11 delta +0.17 not separated
spread 0.08 delta +0.08 not separated
Only the third repeat separates, with B ahead at +0.33. That is the one that gets posted. The other four say nothing, and two even lean the other way. The fix is to state the budget and say what gap it can tell apart. The next repeat of a small test can take the win back.
Plan a comparison inside a budget
Suppose you have 240 model calls and the team cares about a gap of 0.05. plan.py takes the noise the pilot measured and turns it into a spread for each way of splitting the budget:
def spread(run, between, cases, trials):
return sqrt((between + run / trials) / cases)
def smallest_gap(run, between, cases, trials):
wide = RULES["spread_multiple"] * spread(run, between, cases, trials)
return max(RULES["min_delta"], wide)
def calls_for(run, gap):
"""model calls, both prompts, to separate a gap of this size"""
pairs = run * (RULES["spread_multiple"] / gap) ** 2
return 2 * ceil(pairs)
plan: 240 calls, run noise 0.23, case-to-case 0.01
cases trials calls spread smallest gap
60 2 240 0.05 0.09
40 3 240 0.05 0.09
24 5 240 0.05 0.10
12 10 240 0.05 0.10
a gap of 0.05 needs 752 calls
The spread is 0.05 in every row, because cases times trials times two prompts is 240 however you split it, and here the run noise (0.23) dwarfs the case-to-case part (0.01). So the smallest gap this budget can separate is about 0.09. A gap of 0.05 would need 752 calls. Among the splits, 40 cases with 3 trials is as tight as 60 with 2, while 12 cases with 10 trials would only speak for 12 tickets. So fix the rule before the run: a delta of at least 0.09, and smaller gaps reported as not separated. A small budget can still be honest if the claim fits what it can separate. For the classic A/B testing side of this, see A/B tests for ML models.
The traps
- Run each prompt once and pick the higher score. The winner changed between two runs.
- Give each prompt its own cases and compare the means. Case difficulty then mixes into the gap; pairing removes it.
- Report the mean and skip the spread. A against itself showed a gap of -0.12.
The design that holds up: the same cases, several trials per case, the spread read first, and a rule fixed before the run.
Recap
| Habit | Why | In this run |
|---|---|---|
| Trials per case | One prompt moves on its own | A moved 4, B moved 3 across 5 runs |
| Paired cases | Both prompts, same cases | One difference per case |
| Spread first | Shows how far the gap could wander | 0.05, delta +0.14: separated |
| Rule before the run | Stops picking the lucky repeat | 240 calls separate about 0.09 |
The project files for this lesson are in the community, free to join.
StudyEasy AI Community
Learn AI engineering, share what you build, and connect with other learners.
Free resources: lesson files, notebooks and code
Ask questions and join engineering discussions
Meet real people learning and building with AI
Related course on Udemy
Claude Certified Architect - Professional (CCAR-P) Exam Prep
Architecting with Claude: design, models, context, integration, evals, governance and stakeholders.View on Udemy ↗: Claude Certified Architect - Professional (CCAR-P) Exam Prep (paid course, opens in a new tab)Related posts
From ML Metrics to LLM Evals: Same Ruler, New Targets
Precision and recall don't disappear when you build with LLMs; they move. A spam filter at 0.75/0.75, precision@3 and recall@3 on six help-desk documents, exact match vs a key-fact check on two written answers, and the rubric that replaces a single label.
Why You Cannot Ship an LLM Feature Without an Eval: Five Parts, Three Graders, One Tiny Eval
A friendlier prompt looked better on three questions and broke on others. An eval catches that: a fixed set of cases, a grader, a pass rate and a threshold. A tiny Python eval scores two prompt versions on the same six questions: v1 passes 83% and ships, v2 passes 50% and is blocked.
Building a Golden Dataset for LLM Evals: Cases, a Schema, a Coverage Table and a Seeded Split
The answer key for a support bot: 24 cases in one JSONL file, from 12 past tickets, 8 edge cases and 4 attacks. A Pydantic schema catches 4 problems in a broken file, a stats table finds that payments and account have no hard case, and a seeded split gives the same 16 dev and 8 test cases every time.
Retrieval Evals: Score the Retriever With Recall@K, MRR and nDCG Before Blaming the Model
When a RAG answer is wrong, check the retriever first. Score two retrievers on 24 graded queries with Recall@5, MRR and nDCG@5: overall there's no clear winner (0.757 vs 0.819, 0.854 vs 0.826, 0.769 vs 0.782), but the paraphrase slice drops to about 0.5 for both, and one query scores zero everywhere.
