Designing an experiment to compare prompts and models

Study time
≈ 2 h (estimate)
Needs
L2-M06-L05
Updated
2026-11-04

Progress is saved in this browser only. No account, nothing is sent to a server.

Draft · reviewed by AI, not yet by a person. Content may change. English translation: AI-assisted, not human-reviewed.
On this page

Module: L2-M07 · Duration: ~120 min (estimate, including the independent exercise) · Previous: L2-M06-L05 · Next: L02

1. Introduction

"The new prompt is 5 points better" or "the new model wins" usually appears after a single run. These claims can be trusted only when you know in advance: what changed, what is measured, how many questions, how big a difference counts as meaningful, and how the decision is made. If those are chosen after seeing the results, a favourable reading can almost always be found. This lesson teaches how to write a comparison plan before there is any data, check it with a lint, compute the sample size, keep selection data apart from confirmation data, and see why picking the best variant out of many inflates its score.

The earlier modules produced the score of one system with a bootstrap interval; L2-M07 asks whether the scores of two systems really differ, and then turns the answer into a process that can be repeated. Every system in the lab is a simulation (a table of skill numbers and SHA-256 coin flips with known probabilities), so the true difference can be computed exactly; the numbers are not properties of a real model. The product of the lesson: a comparison plan that passes the lint and is frozen with a hash.

2. Learning objectives

  1. Write a comparison plan with every field and run the lint to find what is missing. Practice: §8.2 part A, §9 (TODO 3).
  2. Keep one factor changing at a time and pin the model version with a dated id. Practice: §8.3 (line 2), §9 (TODO 3).
  3. Compute the number of items needed from the difference to detect, the variance, the significance level and the power. Practice: §8.2 part B, §8.3 (line 3), §9 (TODO 1).
  4. Separate selection items from confirmation items by item id, explain the winner's curse and compute the false positive probability when many variants are tried. Practice: §8.2 parts C and D, §8.3 (lines 4 and 5), §9 (TODO 2).
  5. Detect deviations from the frozen plan. Practice: §8.3 (lines 1 and 6).

3. Prerequisites and tools

  • L2-M01-L04 (confidence intervals, sample size, power), L1-M06-L04 (p-values, many cases), L2-M02-L05 (dataset fingerprint, release gate). Code lab code-labs/l2-m07.
  • Disambiguation. The practical margin (margin, Vietnamese "biên thực tế") is the threshold that changes a decision; it is different from the margin of error (half the width of an interval, L2-M01-L04) and from an edge case (L2-M02). Baseline here is the system currently in use, set next to the candidate; it is not the "trivial baseline" of L2-M03 (a do-nothing rule). Power has the same meaning as in L2-M01-L04: the probability that an experiment detects a real difference. Regression is quality getting worse between two versions (L2-M03-L05), not statistical regression analysis. The earlier policy still stands: the judge only flags or ranks, and a person reviews and decides.

4. Concept explanation

4.1 A comparison is an experiment

Miller (Anthropic) opens the paper by observing that evaluations are at heart experiments, yet the literature on evaluations mostly ignores how other fields analyze and plan experiments [R1]. He treats the questions of an eval as random draws from a "super-population" of unseen questions, so a score has sampling error [R1]. A comparison consists of: a question, a baseline, a candidate, the factor that changes, a primary metric (the single number that decides the conclusion), a dataset, the number of runs per item, and a decision rule.

Pre-registration means writing down the question and the analysis plan before seeing the results. Nosek et al. describe it as a way to tell "prediction" apart from "postdiction", because hindsight bias makes people confuse the two [R2] (abstract only). The lab applies a small version: the plan is a dict, plan_hash is its SHA-256, recorded somewhere the person running the experiment cannot edit (a commit, a ticket). The hash proves the plan was not modified; it does not prove the plan was written before the data: that needs a timestamp from outside the lab.

Lifecycle of a comparison plan: the comparison question → a plan (one factor, primary metric, δ, n, decision rule) → plan lint. If it finds problems, go back and fix the plan; if clean, freeze it with plan_hash → run on the confirmation items → compare the run with the plan to find deviations → report and a person's decision.
Diagram: A comparison is an experiment

4.2 One factor at a time, and pinning the version

If both the model and the prompt change, the difference cannot be attributed to either. The lab checks config_diff: between the baseline and the candidates, exactly one of model and prompt differs (shift, the simulator's offset, is not considered), and it matches the declared changed_factor.

The model must be pinned with a dated id, such as tutor-a-2026-03-01. OpenAI's documentation says snapshots within the same model family can give different results and advises pinning production to a specific snapshot, with a test set for model upgrades [R5]. Anthropic's documentation notes that models are deprecated and then retired, that requests to a retired model fail, and advises testing early with the new model [R6]. An alias such as latest can change meaning between two runs without anyone editing anything. The lint only checks that the id ends with a date (PINNED); it does not know whether the model exists or has been retired.

4.3 The practical margin

Effect size here is simply the difference between two pass rates, in percentage points. Statistical significance asks whether the data are compatible with "no difference"; practical significance asks whether the difference is large enough to change a decision. The plan records in advance alpha (the p threshold, 0.05 in the lab) and margin (the practical margin, 0.05 in the sample plan, 0.02 in other demos; chosen from product risk, not from the data).

Do not mix up the two numbers: δ is the difference the experiment must be powerful enough to detect (used to compute n, §4.4); margin is the threshold that changes the decision (used to read the interval). For the interval to clear the margin with enough power, δ usually has to be larger than the margin.

4.4 How many items are needed

Miller gives a sample size formula for a paired comparison, n = (z_{α/2} + z_β)² × (ω² + σ²_A/K_A + σ²_B/K_B) / δ², where δ is the difference to detect, z_β corresponds to β = 1 − power, K is the number of samples per question and ω² is the variance of the difference between the two conditional mean scores of each question [R1]. The lab uses the compact form required_n(var_diff, delta, alpha, power), where var_diff is the variance of the per-item score difference (with K runs, an item's score is the mean of the K runs). That is the lab's reading, consistent with the variance of the per-question difference in the paper [R1], not a verbatim quotation. The result is rounded up; z comes from statistics.NormalDist. Miller's example (fictional parameters, δ = 0.03) gives about 969 questions, and he concludes that new evals should have at least about 1000 questions to have good detection ability [R1].

var_diff must come from a pilot run or from old data; in the lab it is computed exactly because the probabilities are known. Consequence: n is proportional to 1/δ², and several runs per item only reduce the noise part of the variance, not the part that differs between items. With a non-inferiority rule (lower bound ≥ −margin, L04), what has to be detected is the true difference plus the margin: if the true difference is 0 and the margin is 0.05, n is as for δ = 0.05, that is 471 items with var_diff 0.15 (§8.3, line 3).

5. Technical deep dive

5.1 Keeping selection items apart from confirmation items

Choosing a prompt on one set and then reporting the score on the same set gives an optimistic score. Dwork et al. note that holdout data are often reused (for example to tune parameters), and that this is known to cause overfitting to the holdout set [R4]. The lab splits the items into dev (selection) and held-out (confirmation) with split_items, by hashing the item id, not by position: when the dataset gains items, the old items stay on their old side. With v1 (200 items) the result is 65 dev and 135 held-out; v2 (20 added pii items) keeps every v1 item on its side. assert_disjoint raises an error if an item is on both sides.

5.2 Trying many variants: the winner's curse and the false positive probability

Try 12 prompt variants of A (data/variants.json): ten are exactly as good as A, one is 2 points better, one is 2 points worse. The winner's curse: picking the best variant on a noisy sample inflates its score, because "luck" also contributes to its win. Over 40 repeated experiments (a different seed each time), the winner on dev beats A by 0.052 on average; rerunning that variant on the confirmation items gives 0.002, and the true difference of the winners is also 0.002 (§8.2 part D; simulation).

At the same time the family-wise error rate rises: if all m "no difference" hypotheses are true and the tests are independent, the probability of at least one p ≤ α is 1 − (1 − α)^m; with m = 12 and α = 0.05 it is 0.460. Demšar states exactly this problem: when many tests are made, some hypotheses are rejected by chance, so listing every "significant" one is meaningless [R3]. In those 40 experiments, 15 had at least one variant with p ≤ 0.05 without correction (15/40 = 0.375), and after Holm correction only 1 did. The value 1 − 0.95^10 = 0.401 for ten independent null tests is only an idealized reference point and cannot be compared directly: 15/40 includes the two ±2-point variants, the tests share the baseline scores, and the exact sign test has a size below α. With m tests, Bonferroni compares p with α/m [R3]; Holm sorts the p-values in ascending order, compares the j-th with α/(m − j + 1) and stops at the first one that fails. Demšar notes that Holm is more powerful than Bonferroni-Dunn (which divides α by the number of comparisons against one control) and needs no extra assumptions [R3]; his setting is comparing many classifiers; the lab reuses the procedure for many variants on one dataset. The plan records the number of comparisons and the correction method.

5.3 The plan lint and deviations

lint_plan returns error codes: MISSING:<field>, UNPINNED_MODEL, NOT_ONE_FACTOR, NO_SINGLE_PRIMARY, BAD_ALPHA, BAD_MARGIN, OPTIONAL_STOPPING (a stopping rule other than fixed_n: stopping when "significant" breaks the p-value), COMPARISON_COUNT, MULTIPLE_WITHOUT_CORRECTION, DATASET_NOT_PINNED, UNDERPOWERED. deviations(plan, run) compares a run with the frozen plan: PLAN_CHANGED_AFTER_FREEZE, DATASET_DIFFERENT, CHANGED:<field>, UNPLANNED_METRIC:<name>, MORE_COMPARISONS_THAN_PLANNED, PRIMARY_NOT_REPORTED (the primary metric is not reported: a sign that the metric was switched midway). An empty code list means these checks found nothing, not that the plan is good.

6. The QA perspective

6.1 What the lint does not check, and the questions to ask on hearing "B is better than A"

The lint does not know: whether the hypothesis is reasonable (a decision_rule of "ship it" still passes); whether the margin matches the risk; whether the plan was written before the data; whether the model exists. UNDERPOWERED uses only the plan's alpha and δ, not α/m or the margin. With the sample plan (δ = 0.10, var_diff 0.15), 118 items are enough for one comparison; four candidates with Bonferroni correction (α = 0.05/4) need 168; a non-inferiority rule with a true difference of 0 needs 471 (§4.4). The lint still reports clean for all three cases with 200 items.

On hearing "B is better than A", ask: (1) did exactly one factor change; (2) is the model pinned; (3) what is the primary metric and did it change midway (deviations catches it when it is not reported); (4) were n, δ and the margin computed in advance; (5) how many variants were tried and was there a correction; (6) was the score reported on selection items or confirmation items; (7) are there any deviations from the plan. Without an answer to any one of these, the conclusion is only a suggestion; the decision-maker is a person.

7. Real-world scenarios

Scenario 1 (fictional): "Twelve prompts, one winner". The HocVui Tutor team tried 12 ways of writing the hint prompt on 100 questions, picked the highest (+5 points) and reported "5 points improvement". QA asked which items the score was measured on and how many variants had been tried; rerunning the winner on new items gave a result near 0. The team recorded the number of variants in the plan, applied Holm correction, and reported scores only on the confirmation items.

Scenario 2 (fictional): "Changing both model and prompt, and the latest alias". A ticket said "the new model and new prompt are better". The baseline called the alias tutor-a-latest, which had been repointed between two runs. The lint reported UNPINNED_MODEL and NOT_ONE_FACTOR. The team split it into two experiments, one factor each, with dated ids.

8. Hands-on tutorial

8.1 Setup

cd academy-content/code-labs/l2-m07
python3 -m venv .venv && source .venv/bin/activate     # Windows: .venv\Scripts\activate
python -m pip install -r requirements.txt
python -m pytest            # 79 passed

8.2 Run the demo

python -m lab.demo l01

Output (copied from a real run on Python 3.14.6 and 3.12.14, 2026-11-04; the two versions give identical output). Every system is a simulation:

A. plan lint: []  hash: 98a9a5db35ec
   unpinned baseline: ['UNPINNED_MODEL']
   prompt changed too: ['NOT_ONE_FACTOR']
   n_items = 50: ['UNDERPOWERED']
   stop when significant: ['OPTIONAL_STOPPING']
B. items needed for 80% power, alpha 0.05 (var = variance of the per-item difference)
   S vs A: true gap 0.127, runs per item 3, var 0.1083, items needed 53
   B vs A: true gap 0.039, runs per item 1, var 0.2878, items needed 1486
   B vs A: true gap 0.039, runs per item 5, var 0.0596, items needed 308
C. dev/held-out split of v1: 65 135  v2 keeps every v1 item on its side: True
D. 40 experiments, 12 prompt variants of A (ten are exactly as good as A) (simulated)
   winner on dev: mean gain 0.052  same winner on fresh runs: 0.002  true gain of the winners: 0.002
   experiments with at least one p <= 0.05: 15 of 40; after Holm: 1 ; chance of at least one p <= 0.05 among 12 independent tests, all null: 0.460

Reading the output: A: the sample plan is clean and four broken plans are caught. B: the number of items for 80% power (a true gap of 0.127 needs 53 items; 0.039 needs 1486 items with one run, 308 with five runs). C: the split by item-id hash. D: the winner on dev (0.052) shrinks to near 0 on fresh data.

8.3 Try it yourself

Save it as try_l01.py in the lab's root folder (next to lab/, not inside lab/), run python try_l01.py, then delete the file:

import copy
from fractions import Fraction as F
from lab import data, design, selection as SEL, simulate as S
from lab.stats import bonferroni, holm, required_n

plan = data.load_json("plan_example.json")
frozen = design.plan_hash(plan)
loose = copy.deepcopy(plan)
loose["margin"] = "1/40"
print(design.plan_hash(loose) == frozen, design.lint_plan(loose))

two = copy.deepcopy(plan)
two["candidates"][0]["prompt"] = "p02"
two["baseline"]["model"] = "tutor-a-latest"
print(design.config_diff(two["baseline"], two["candidates"][0]), design.lint_plan(two))

print(required_n(0.15, 0.10), required_n(0.15, 0.10, 0.05 / 4), required_n(0.15, 0.05))
p = [F(1, 100), F(1, 70), F(1, 30), F(1, 2)]
print(bonferroni(p, F(1, 20)), holm(p, F(1, 20)))

items = S.make_dataset("v1")
dev, held = SEL.split_items(items)
side = {i["id"]: "dev" for i in dev}
print(len(dev), len(held), side.get("CO001", "held"), side.get("CO002", "held"))

run = {"plan_hash": frozen, "dataset_fingerprint": plan["dataset"]["fingerprint"], "n_items": 150, "reps": 3,
       "baseline": plan["baseline"], "candidate": plan["candidates"][0], "alpha": "1/20", "margin": "1/20",
       "test": plan["test"], "reported_metrics": ["pass_rate", "bleu"], "n_comparisons": 1}
print(design.deviations(plan, run))

Output (identical on Python 3.14.6 and 3.12.14):

False []
['model', 'prompt'] ['UNPINNED_MODEL', 'NOT_ONE_FACTOR']
118 168 471
[True, False, False, False] [True, True, False, False]
65 135 held dev
['CHANGED:n_items', 'UNPLANNED_METRIC:bleu']

Reading it: line 1: loosening margin after the freeze changes the hash (False) but the lint is still empty: the lint only checks shape. Line 2: two factors differ and the baseline is an alias. Line 3: the sample size for δ = 0.10 (118), for the same δ with α = 0.05/4 (168) and for δ = 0.05 (471). Line 4: with four p-values, Bonferroni (comparing with 0.0125) rejects one, Holm rejects two. Line 5: CO001 is in held-out, CO002 is in dev. Line 6: two deviations: n_items changed and there is a metric outside the plan.

8.4 Run the lesson's tests

python -m pytest tests/test_l01_design.py -v

Result: 20 passed. Read test_each_defect_is_named and test_the_winner_of_twelve_variants_shrinks_on_fresh_data. The tests run on in-memory values and the lab's data.

8.5 Troubleshooting

Symptom Cause Fix
MISSING:<field> The plan lacks a field Add the field; the lint stops at this error and does not yet run other checks

9. Independent exercise

Problem: Fix a broken comparison plan before there is any data.

Requirements: complete exercises/test_l01_design.py:

  1. TODO 1: N_NEEDED: the number of items needed to detect the plan's δ, with its alpha, power and assumed_var_diff.
  2. TODO 2: FWER: the probability (a Fraction) that at least one candidate is "significant" when none of the four is better, the tests are independent, with no correction.
  3. TODO 3: FIXED: a copy of the plan that lint_plan accepts. Keep the question, the baseline prompt and the four candidates, δ, alpha and power unchanged; change only what the errors force you to change.

Test data: exercises/ex_plan.json (a simulated plan, four prompt variants of one system against the current prompt).

Deliverable: the three variables above, in the file exercises/test_l01_design.py itself.

Acceptance criteria: python -m pytest exercises/test_l01_design.py passes (3 tests): the numbers recomputed with lab.stats, and FIXED is lint-clean while keeping the fields named above, with a dataset that is a released version with a real fingerprint and is large enough. The tests do not check whether FIXED makes sense for the product, and the lint does not factor the correction into the sample size: a plan that passes the lint may still lack power after correction and must be recorded as a limitation (§6.1).

Hints: TODO 1 and 2: check required_n and fwer against the formulas in §4.4 and §5.2. TODO 3: run lint_plan on the original, fix each error code and run it again; the dataset fingerprint is in registry.pinned().

10. Knowledge check

0/16 done · Results are kept in this browser only.

P02 · True or false

The team records the plan's plan_hash in the ticket. That hash proves the plan was written before the data existed.

P04 · Select all that apply

Take plan_example.json (one candidate, alpha 1/20, δ 0.10, var_diff 0.15, power 0.8, n_items 200, dataset v1 pinned) and edit it: baseline {"model": "tutor-a", "prompt": "p00"}; three candidates {"model": "tutor-a-2026-03-01", "prompt": "p01"}, p02, p03; changed_factor is "prompt"; stopping_rule is "until_significant"; correction is "none"; n_comparisons is 3. Select every code that lint_plan returns.

P05 · Put in order

Put the steps of a planned comparison in order, from before the data exists to the report.

  1. Run lint_plan and fix each error code until the list is empty
  2. Freeze: compute plan_hash and record it where the runner cannot edit it
  3. Run deviations to compare the run with the frozen plan
  4. Report the primary result with its interval and the deviations, so that a person decides
  5. Run the comparison on the confirmation items (held-out)
  6. Write the plan: question, baseline, candidate, one changed factor, primary metric, δ, margin, n and decision rule

P06 · Match

Match each deviations code with what it reports.

P07 · Spot the bug

The function below separates the selection items (dev) from the confirmation items (held-out) but ruins the confirmation score when the dataset gains items. Find the bug.

def split_items(items):
    cut = len(items) * 3 // 10
    return items[:cut], items[cut:]

P08 · Short answer

A plan uses a non-inferiority rule: the candidate may replace the baseline only if the lower bound of the interval is ≥ −0.04. Assume the true difference is 0, var_diff 0.18, alpha 0.05, power 0.8, one comparison. How many items are needed? Are 300 items enough, and what should be done if only 300 items are available?

P09 · Essay

Write 5-8 sentences reviewing a report (simulated): a team tried 6 prompt variants of the system in use on 150 items, picked the variant with the highest score (4 points above the old system) and reported "the new prompt improves by 4 points", the score computed on the same 150 items used to choose it. Name the phenomenon, the false-positive probability if all six variants are truly no better (use fwer(6, 1/20)), and two things to put in the plan.

P11 · Recall

Lesson: L2-M01-L04

According to L2-M01-L04, what does it mean for an experiment to have 80% power to detect a true difference δ = 0.06?

P12 · Recall

Lesson: L1-M06-L04

A comparison returns p = 0.03. This means the probability that the two systems are really the same is 3%.

P13 · Multiple choice

The baseline is {"model": "tutor-a-2026-03-01", "prompt": "p00"} and the plan declares changed_factor as "prompt". Which candidate makes lint_plan report neither NOT_ONE_FACTOR nor UNPINNED_MODEL?

P14 · Select all that apply

Select every correct statement about separating the selection items (dev) from the confirmation items (held-out) in the lab.

P15 · Match

Match each term with its role in a comparison.

P16 · Short answer

A plan (plan_example.json) has one candidate, alpha 1/20, primary metric pass_rate, secondary metrics p95_latency_ms and cost_per_success. A run has the right plan_hash, a dataset fingerprint different from the plan, alpha 1/10, reports cost_per_success and rouge (and does not report pass_rate) and makes 2 comparisons. Which codes does deviations return, and what should the team do with them?

11. Summary

  • Concepts: a plan frozen with a hash; one factor, a pinned model; δ differs from margin; sample size; the selection set kept apart from the confirmation set; the winner's curse; Holm correction.
  • Skills: writing and linting a plan, computing n, splitting by item id, counting comparisons, detecting deviations.
  • Traps: reporting the score on items used for selection; changing two factors; the latest alias; stopping when "significant"; trusting an empty lint as a good plan.
  • You can now: hear "the new prompt is 5 points better" and ask the seven questions in §6.1.

12. References

ID Title Publisher URL Accessed Relevance
R1 Adding Error Bars to Evals: A Statistical Approach to Language Model Evaluations (Miller, 2024) arXiv https://arxiv.org/abs/2411.00640 (full-text PDF read: https://arxiv.org/pdf/2411.00640) 2026-11-04 Read in full: super-population, sample size formula (Eq. 9), the 969-question example
R2 The preregistration revolution (Nosek et al., 2018) PNAS, via Europe PMC https://doi.org/10.1073/pnas.1708274114 2026-11-04 Abstract-only (Europe PMC API query); definition of pre-registration
R3 Statistical Comparisons of Classifiers over Multiple Data Sets (Demšar, 2006) JMLR https://jmlr.org/papers/v7/demsar06a.html (PDF: https://jmlr.org/papers/volume7/demsar06a/demsar06a.pdf) 2026-11-04 Read in full: multiple tests, family-wise error, Holm, Bonferroni-Dunn
R4 Preserving Statistical Validity in Adaptive Data Analysis (Dwork et al.) arXiv (v3, 2016) https://arxiv.org/abs/1411.2664 2026-11-04 Read the abstract and the introduction of the PDF: reusing a holdout set causes overfitting
R5 Prompt engineering (OpenAI API docs) OpenAI https://platform.openai.com/docs/guides/prompt-engineering 2026-11-04 Read the page text: pinning snapshots, a test set when changing models
R6 Model deprecations (Claude Platform Docs) Anthropic https://docs.anthropic.com/en/docs/about-claude/model-deprecations 2026-11-04 Read the page text: deprecated, retired, test early with the new model

Key terms (English ↔ Vietnamese)

English Tiếng Việt
Comparison plan Kế hoạch so sánh, viết trước dữ liệu
Pre-registration Đăng ký trước: ghi kế hoạch trước khi thấy kết quả
Primary metric Chỉ số chính: số duy nhất quyết định kết luận
Pinned model id Mã model ghim: có ngày, khác bí danh
Effect size Độ lớn hiệu ứng: ở đây là hiệu hai tỷ lệ pass
Statistical vs practical significance Ý nghĩa thống kê / thực tế (so với margin)
Dev set / held-out set Tập chọn lựa / tập xác nhận
Winner's curse Lời nguyền người thắng: điểm của biến thể thắng bị thổi phồng
Family-wise error rate Xác suất có ít nhất một dương giả trong cả họ phép thử
Holm correction Hiệu chỉnh Holm