You changed a prompt. Is the bot better now? Reading a few replies and nodding is how most teams decide, and it’s how regressions reach users. An eval replaces the nodding with a score you can rerun on every change. But a score is a measurement, and measurements go wrong in two ways: they measure the wrong thing, or they’re too noisy to trust. Trust a score only if it measures what you care about, on enough examples to tell a real change from luck. Here you’ll grade answers with the classic metrics, catch them rewarding a wrong answer, and find out how many test questions it takes to see a real improvement.
Start with an eval set#
An eval set is a list of inputs, each with a way to tell whether an output is good: a reference answer, a fact that must appear, a format it must follow. The best inputs are real ones: questions users actually asked, the awkward edge cases, and every failure someone has reported. Keep the set in version control next to the prompt, run it on every change, and you’ll know what each change did.
Then you need a grader: something that turns an output into a score. There are three kinds, and you’ll usually want more than one.
- Code checks. Exact match for a label, valid JSON, a citation present, a number within range. Fast, free and repeatable, but they only test what you thought to test.
- Overlap with a reference. Count how many words an output shares with a human-written answer. BLEU (from machine translation, 2002) and ROUGE (from summarisation, 2004) are the classics, and still appear in papers and dashboards.
- A model as the judge. Ask a strong LLM to grade each output against a rubric. Flexible, but it needs checking itself.
When a grader rewards the wrong answer#
A shop’s support bot is asked about returns. The reference answer says 30 days and a full refund. Here are five answers the bot might give, graded three ways.
Predict first
One answer copies the reference but says 14 days instead of 30. Another gets every fact right in different words: “Returns are accepted for a month after purchase, and you’ll get all your money back.” Which does BLEU score higher?
sacrebleu and rouge-score Python packages (checked against both). Pick Write your own to test any answer.ROUGE-L looks for the longest run of words the two answers share in the same order (the highlighted words), and BLEU counts matching runs of one to four words. Both reward answers that look like the reference, so the wrong number scores 0.92 on ROUGE-L and the most helpful answer scores lowest of all on BLEU, because every extra helpful word counts against it. These metrics were designed to compare whole systems over thousands of sentences, ideally with several references each; on one short answer they mostly measure phrasing.
The quick check, "30 days" in answer, does better: it catches the wrong number. But it fails the correct “a month” answer and passes the one that promises 30 days and then refuses refunds. Every grader has blind spots; find them by grading answers you already know are right and wrong. That small set of known answers is how you test the grader before you trust it with your prompt.
How many questions is enough?#
A common starting point is 30 to 50 test questions. That’s enough to catch a change that breaks things badly. Is it enough to see a change that makes things a little better?
Predict first
Version B of your prompt really answers 85% of questions correctly; version A answers 80%. You test both on the same 50 questions. How often does A tie or beat B?
Look at the grid before the scores. Most questions are green or grey: both versions pass, or both fail. Those questions can’t tell the versions apart. In the first run of 50, the whole verdict rests on 6 questions where they disagree, A alone passing 2 and B alone 4. Six questions can’t prove anything: a split that uneven happens often between two equally good prompts.
The 1,000 re-runs show the same thing. With 20 questions, B fails to come out ahead 39% of the time; with 50, 23%; with 100, 12%; with 300, 1.4%; with 1,000, essentially never. Each single score is fuzzy too: with 50 questions, a measured 80% means the true rate is probably somewhere between 67% and 89%. A difference smaller than the noise isn’t a result. Use enough questions for the size of change you care about, compare versions on the same questions, and count the questions where they disagree.
Habits that make evals worth having#
- Read the failures, not just the score. The questions where the new version fails and the old one passed tell you what you broke.
- Keep some questions back. If you tune a prompt until it aces the eval set, the set stops measuring anything else. Hold back a part you only run before release.
- Grow the set from production. Every complaint or bad answer becomes a new test question, so the same mistake can’t come back unnoticed.
- Track more than correctness. Length, cost and response time change with prompts too.
In code#
The figure’s metrics, with the Python packages it was checked against (pip install sacrebleu rouge-score):
from sacrebleu import sentence_bleu
from rouge_score import rouge_scorer
reference = "Yes, you can return it within 30 days for a full refund."
answers = {
"same facts, new words": "Sure! Returns are accepted for a month after purchase, and you’ll get all your money back.",
"wrong number": "Yes, you can return it within 14 days for a full refund.",
}
rouge = rouge_scorer.RougeScorer(["rougeL"])
for name, answer in answers.items():
bleu = sentence_bleu(answer, [reference]).score
rl = rouge.score(reference, answer)["rougeL"].fmeasure
print(f"{name:22} BLEU {bleu:5.1f} ROUGE-L {rl:.2f}")
# same facts, new words BLEU 4.8 ROUGE-L 0.14
# wrong number BLEU 78.3 ROUGE-L 0.92To compare two versions run on the same questions, count the disagreements and test them. The test asks how often a split at least this uneven would happen if the two versions were equally good (that’s the p-value; small means unlikely to be luck):
from scipy.stats import binomtest
def compare(results):
"""results: one (a_passed, b_passed) pair per question, both versions on the same questions."""
a_only = sum(a and not b for a, b in results)
b_only = sum(b and not a for a, b in results)
p = binomtest(b_only, a_only + b_only).pvalue # exact McNemar test
print(f"A alone {a_only}, B alone {b_only}, p = {p:.2g}")
compare([(1, 1)] * 38 + [(1, 0)] * 2 + [(0, 1)] * 4 + [(0, 0)] * 6) # 50 questions
compare([(1, 1)] * 600 + [(1, 0)] * 40 + [(0, 1)] * 80 + [(0, 0)] * 280) # 1,000 questions
# A alone 2, B alone 4, p = 0.69
# A alone 40, B alone 80, p = 0.00033What to remember
- An eval is an eval set plus a grader, run on every change, so “is it better?” has an answer you can repeat.
- Word-overlap metrics like BLEU and ROUGE reward looking like the reference, even when the facts are wrong; test every grader on answers you know are right and wrong.
- Small eval sets are noisy: compare versions on the same questions, count where they disagree, and use enough questions for the change you want to see.