Your Prompt A/B Test Said +8%. Run It Again and It Says +4%: The Sample Size Your Eval Actually Needs
I ran the same 400-item prompt eval five times against a population where I already knew the answer. Prompt B was exactly 6.0 points better than prompt A, always, by construction.
The five results: +8.0, +4.3, +7.3, +7.8, +4.8 points. Same items. Same judge. Same prompts. Three of those five runs would have shipped B under a rule of "the 95% interval's lower bound must clear +2 points." Two would have kept A and written a note that B "didn't help."
That spread is not a tooling bug. That is what 400 items buys you, and most prompt A/B tests I see in the wild are run on twenty items or fewer.
Below is what I measured, with the code to reproduce it. The setup is a synthetic eval population with a known true effect, so power and false-positive rates are measured rather than asserted: 200,000 items, three difficulty bands (30% easy, 20% hopeless, 50% discriminating, all seeded), standard library only, Python 3.12.16, no API calls, 278 seconds for the full run, 23 unit tests.
What a sample size actually buys
A prompt comparison is a two-arm experiment on pass/fail outcomes. If the baseline passes 63.5% of items, here is the resolution you get:
| items per arm | 95% CI half-width | power to detect +8 pts | smallest detectable gain at 80% power |
|---|---|---|---|
| 20 | ±21.9 pts | 1.8% | >40 pts |
| 50 | ±13.6 pts | 15.0% | 30 pts |
| 100 | ±9.6 pts | 34.0% | 20 pts |
| 200 | ±6.7 pts | 59.5% | 15 pts |
| 400 | ±4.8 pts | 89.8% | 10 pts |
| 800 | ±3.4 pts | 99.5% | ~5 pts |
Read the first row again. Twenty items per prompt gives you an interval ±21.9 points wide, and it cannot detect anything smaller than a 40-point difference. The "B won 14 to 11, ship it" test is not a weak test. It is not a test.
Two details worth noticing in that table, because they are the reason many teams conclude the opposite:
- At n=20 the false-positive rate is 1.8%, not 5%. The exact paired test simply cannot reach significance when few items disagree - it needs at least six items flipping one way and zero the other. So a small test is not dangerous by being trigger-happy; it is dangerous by being quiet, and quiet reads as "no difference" in the meeting.
- The gain you can detect shrinks with the square root of n. Doubling items from 200 to 400 moves the threshold from 15 points to 10. Doubling again to 800 gets you to about 5. If your prompt change is a real but modest 4 points, you need roughly a thousand paired items, and no amount of clever statistics replaces them.
Your test only uses the items that disagree
Here is the part that makes paired evals cheap: the test statistic counts only the disagreements.
def paired_counts(a: list[bool], b: list[bool]) -> PairedResult:
both_pass = a_only = b_only = both_fail = 0
for x, y in zip(a, b):
if x and y:
both_pass += 1
elif x:
a_only += 1
elif y:
b_only += 1
else:
both_fail += 1
return PairedResult(len(a), a_only, b_only, both_pass, both_fail)
def mcnemar_exact(b: int, c: int) -> float:
"""Exact two-sided McNemar p-value from the discordant pair counts."""
n = b + c
if n == 0:
return 1.0
k = min(b, c)
tail = sum(math.comb(n, i) for i in range(k + 1)) / 2.0 ** n
return min(1.0, 2.0 * tail)
Run 1 of the five above looked like this: 400 items, A passed 64.3%, B passed 72.3%, 25 items only A passed, 57 only B passed, p = 0.00053. Everything else - 318 items - was information about how hard the eval is, not about which prompt is better.
That is also why you should report a_only and b_only next to your p-value. "+8 points, p = 0.0005" reads like a property of the prompts, but it is a property of the prompts and the 82 items that disagreed. Anyone can re-derive the p-value from 25 and 57; nobody can re-derive it from 0.0005.
Pairing is free power
Grading the same items under both prompts costs the same number of model calls as grading different items under each. It just tells you more:
| items per arm | power, paired | power, unpaired | SD of measured delta, paired vs unpaired |
|---|---|---|---|
| 200 | 54.3% | 40.0% | 3.3 vs 4.8 pts |
| 400 | 87.3% | 60.7% | 2.3 vs 3.4 pts |
| 800 | 100% | 90.0% | 1.7 vs 2.5 pts |
Same budget, and at 400 items the paired design turns a 61% chance of noticing a real 8-point gain into an 87% chance. The reason is mundane: item difficulty differs enormously, and when both arms see the same item, that difficulty cancels out of the difference. Unpaired, it lands in your noise term, where it costs roughly twice the items to overcome (800 unpaired items reach the power that 400 paired items do).
If you take one thing from this post: build the item set once, grade it twice, and compare per item. It is the only free upgrade in this whole area.
Looking at the results every day is a decision to raise your false-positive rate
Everyone who runs an eval watches the number. I simulated that too: a true null (both prompts identical), 400 items, and checking the p-value after every 20 items, stopping the first time it drops below 0.05. Measured false-positive rate: 15.9%, against 4.4% when the sample size and the single look were fixed in advance.
The fix is boring: divide the alpha you are willing to spend across the number of looks you plan to take.
for i in range(step, n_max + 1, step):
look = i // step
alpha = 0.05 / look # Bonferroni across looks so far
if paired_counts(a[:i], b[:i]).p_value < alpha:
return True
That restores the rate to 3.5%, and it costs power: 69.5% instead of 89.8% at +8 points. Both numbers are honest. If you plan to stop early, you must pay for it in items, and the Bonferroni line above is the cheapest version of that payment. If you don't plan to stop early, close the dashboard until the run is done.
Five variants, and the winner's curse
"Pick the best of six prompts" is a different question from "compare two", and it is where most teams quietly lose control of their error rate. With five variants against one baseline, all of them truly equal, at 300 items:
| rule | chance of shipping some variant when none is better |
|---|---|
| any variant p < 0.05 | 16.2% |
| Holm-Bonferroni, family alpha 0.05 | 4.0% |
And the price shows up on the other side. With one genuinely better variant (+8 points) among five:
| items | power, naive | power, Holm |
|---|---|---|
| 300 | 51.1% | 27.8% |
| 800 | 90.4% | 75.1% |
def holm(pvalues: dict[str, float], alpha: float = 0.05) -> dict[str, dict]:
items = sorted(pvalues.items(), key=lambda kv: kv[1])
m = len(items)
out, still_rejecting = {}, True
for rank, (name, p) in enumerate(items, start=1):
threshold = alpha / (m - rank + 1)
rejected = still_rejecting and p <= threshold
still_rejecting = rejected
out[name] = {"p": p, "threshold": threshold, "reject": rejected, "rank": rank}
return out
The practical consequence: comparing five variants instead of one costs the winner two to three times the items. At 800 items with Holm you reach 75.1% power for the real winner; a single comparison already has 90.4% at that size. Generate six prompts if you like, but budget for it before you start, not after the winner emerges with p = 0.04.
The judge is part of the instrument
Every number above assumes the pass/fail verdicts are correct. They are not. I took the same paired outcomes and flipped each verdict independently with probability f, then re-measured power at +8 points:
| judge flip rate | power at n=200 | power at n=400 | majority-of-3 at n=400 |
|---|---|---|---|
| 0% | 61.0% | 88.3% | - |
| 5% | 46.0% | 71.0% | 85.7% |
| 10% | 31.0% | 48.7% | 79.0% |
| 20% | 14.0% | 29.0% | 50.0% |
A judge that gets 1 verdict in 10 wrong costs you roughly half your experiment. With symmetric flips like these it barely biases the result - the errors cancel - it just buries the signal in the noise it adds. Real judges also fail in correlated ways (always too lenient on a topic, always strict on a format), and those errors do not cancel.
You can measure your judge's flip rate in an hour: take 50 items, grade them twice under the same prompt, count how often the verdict changes. If it's above 10%, voting three times per item is cheaper than quadrupling the item count, and at a 10% flip rate it recovers most of the loss (79.0% vs 48.7% at n=400). Above 20%, fix the judge.
The decision rule
A p-value does not tell you whether to ship. Here is the rule I use, with both gates written into code: the interval's lower bound has to clear the smallest gain worth having, and the extra tokens have to be paid for by the extra correct answers.
def decide_ship(n, a_only, b_only, both_pass, both_fail, min_gain, tokens_a, tokens_b, price_per_mtok, value_per_correct):
diffs = [0] * (both_pass + both_fail) + [1] * b_only + [-1] * a_only
lo, hi = bootstrap_ci_diffs(diffs, seed=11) # 95%, percentile
delta = (b_only - a_only) / n
extra_cost_per_1k = (tokens_b - tokens_a) * 1000 * price_per_mtok / 1_000_000
gain_per_1k = delta * 1000
break_even = extra_cost_per_1k / gain_per_1k if gain_per_1k > 0 else float("inf")
if lo <= min_gain:
return Decision(False, f"CI lower bound {lo:+.3f} <= min_gain {min_gain:+.3f}", delta, lo, hi, extra_cost_per_1k, break_even)
if break_even > value_per_correct:
return Decision(False, f"break-even ${break_even:.4f} > ${value_per_correct:.4f}", delta, lo, hi, extra_cost_per_1k, break_even)
return Decision(True, "gain clears the threshold and cost is covered", delta, lo, hi, extra_cost_per_1k, break_even)
The five runs again, with B costing 1.72x the tokens of A (1,410 vs 820 per item, at $0.60 per million input tokens):
| run | measured delta | 95% CI | p | decision |
|---|---|---|---|---|
| 1 | +8.0 | +3.8 to +12.5 | 0.0005 | ship |
| 2 | +4.3 | −0.8 to +9.5 | 0.13 | hold |
| 3 | +7.3 | +2.5 to +12.3 | 0.0055 | ship |
| 4 | +7.8 | +3.3 to +12.3 | 0.0013 | ship |
| 5 | +4.8 | +0.5 to +9.3 | 0.042 | hold |
Run 5 is significant at 0.042 and still does not ship, because the interval's lower bound clears only +0.5 points while the threshold is +2. That is the rule doing its job: "significant" answers "is there an effect", not "is the effect big enough to matter".
The cost side was almost beside the point: 590 extra tokens per item is $0.354 per 1,000 items, and at an 8-point gain that is a break-even value of $0.0044 per additional correct answer. If a correct answer is worth more than half a cent to you - and for most products it is - cost is not what blocks this decision. Sample size is. That is the opposite of the intuition that usually stops these tests.
What to write down before you run
The whole post reduces to seven lines you record before the first API call:
- The item set, frozen and hashed. Same items for every arm, and a hash so you know it didn't drift mid-run.
- n, chosen from the table above, from the smallest gain you'd actually act on.
- The metric and the judge, versioned. "Pass" must mean one thing, including the judge model and prompt.
- The decision threshold (
min_gain), in points, decided before you see data. - The variant count and the correction you'll apply to it.
- The discordant counts you'll report (a_only, b_only), not just p.
- No looking until n is reached. If you will look, use a spend-down alpha.
Reproduce it
Environment: Python 3.12.16, standard library only, deterministic seeds (20261202, population seed 20261202), no network, no paid calls. Full experiment run: 284 seconds. Unit tests: 23 passing, 0.85 s.
| file | lines | what it does |
|---|---|---|
| abtest.py | 347 | Wilson and Newcombe intervals, exact McNemar, two-proportion z, paired bootstrap, power/MDE, Holm, cost-aware decision rule |
| simulate.py | 78 | the 200,000-item eval population and paired/unpaired draw functions |
| experiments.py | 381 | E0-E6: the tables above, written to reports/measurements.json |
| tests/test_abtest.py | 176 | 23 tests: known t/Wilson/McNemar values, calibration, Holm ordering, decision gates |
If you want the short version to keep next to your terminal: 20 items tells you nothing, 400 items tells you whether a 10-point gain is real, pair everything, don't peek, and divide alpha by the number of prompts you generated. Everything else is arithmetic on top of those five.
Disclosure: the link below is to my own Payhip store, where I sell the small packs of eval configs, checklists and harness templates I build from these experiments. Nothing in this post is behind it - the code above is complete and the numbers are reproducible from it. If you're wiring this into your own eval loop, the pre-run checklist and the decision-rule config I use are here: Yuya AI Lab on Payhip.
Comments
No comments yet. Start the discussion.