To evaluate LLM output, collect a test set of real inputs with a clear definition of a good answer for each, then score every model or prompt change against it: with code wherever the answer can be checked mechanically, and with a rubric-driven LLM judge, validated against your own human labels, where it can't. "It looked fine on a few tries" is not an evaluation; a pass rate on a fixed test set is.
Why spot-checking isn't enough
LLM output varies between runs and between near-identical prompts, so a handful of good answers says little about the next thousand. OpenAI's evaluation guide names "vibe-based evals", using "it seems like it's working" as the strategy, as a pitfall. A fixed test set gives you a number you can compare before and after every change: a new model, a prompt edit, a different temperature setting.
Step 1: Define what a good answer is
Write the success criteria down before writing tests. Make them measurable:
- Vague: "The summaries should be good."
- Measurable: "Each summary mentions the customer's problem and the agreed fix, is under 80 words, and contains no facts that aren't in the ticket."
Most real tasks have several criteria at once, typically correctness, format, faithfulness to the source, tone and safety. Each one may need a different grading method.
Step 2: Build a test set from real inputs
Anthropic's guide gives three design principles:
- Be task-specific. Mirror your real input distribution, including edge cases: missing or irrelevant input, very long input, hostile input, and ambiguous cases "where even humans would find it hard to reach an assessment consensus".
- Automate when possible. Shape the task so answers can be graded automatically (a label, a number, valid JSON).
- Prioritise volume over quality. In Anthropic's words, more questions with slightly lower-signal automated grading beat fewer hand-graded ones.
For each case, store the input, the expected answer or the facts a good answer must contain, and a tag for the kind of case (normal, edge, adversarial). Sources for cases: production logs (with personal data removed), support tickets, and every bug report about a bad answer. Every failure you fix becomes a regression test.
How many cases?
Enough that the score difference you care about is larger than the noise. Here is the 95% Wilson interval for the same 90% pass rate at three test-set sizes, computed with a short Python script:
| Passed | Pass rate | 95% interval |
|---|---|---|
| 9 / 10 | 90% | 59.6% to 98.2% |
| 45 / 50 | 90% | 78.6% to 95.7% |
| 180 / 200 | 90% | 85.1% to 93.4% |
With 10 cases, a prompt that scores 90% could really be a 60% prompt. Use small sets to find failures fast, and larger ones before decisions like switching models.
Step 3: Grade with code first
Anthropic ranks grading methods by speed and reliability: code-based grading is "fastest and most reliable, extremely scalable" but lacks nuance; human grading is the most flexible but "slow and expensive"; LLM-based grading sits between them. Use code for anything that has a checkable answer:
| Check | Good for |
|---|---|
| Exact or normalised match | Labels, classifications, short factual answers |
| Contains / doesn't contain | Required facts, banned phrases, leaked secrets |
| Parse and validate | JSON against a schema, dates, numbers in range |
| Run it | Generated code against unit tests; SQL against a test database |
| Similarity metrics (ROUGE-L, embedding cosine similarity) | Summaries or paraphrases compared with a reference |
Details matter more than you'd expect. We graded six fake sentiment outputs two ways:
cases = [
{"id": 1, "expected": "positive", "output": "Positive"},
{"id": 2, "expected": "negative", "output": "negative"},
{"id": 3, "expected": "neutral", "output": "The sentiment is neutral."},
{"id": 4, "expected": "negative", "output": "positive"},
{"id": 5, "expected": "positive", "output": " positive\n"},
{"id": 6, "expected": "neutral", "output": "mixed"},
]
exact: out == exp
normalized: out.strip().lower() == exp.lower()
Output of the script:
exact 1/6 passed ids=[2]
normalized 3/6 passed ids=[1, 2, 5]
Strict matching failed two answers that were right but differently cased or padded. Case 3 is right too but wrapped in a sentence, which tells you to fix the prompt or the output format rather than the grader. Cases 4 and 6 are genuine failures. Read failing outputs before trusting any score.
For structured output, check that it parses and has the fields you need. Our JSON check returned:
(True, 'ok')
(False, "missing keys: ['confidence']")
(False, 'invalid JSON: Expecting value: line 1 column 1 (char 0)')
The third case was a reply that started with "Sure! Here is the JSON:". See how to get JSON from an LLM reliably for ways to prevent that.
Step 4: Use an LLM judge for what code can't check
Tone, helpfulness, faithfulness to a source document and "does this answer the question" need judgment. An LLM judge is a second model call that grades the first. OpenAI's guide describes it as "cheaper to run and more scalable than human evaluation". Anthropic's tips for making it reliable:
- A detailed, clear rubric. State exactly what passes and what fails, including automatic-fail conditions.
- Constrained output. Ask for "correct" or "incorrect", or a 1 to 5 score with both ends defined, not free-form opinions.
- Reasoning before the score. Anthropic recommends a grader with extended thinking on, so it reasons before producing the score.
- A different model from the one being graded, which Anthropic's example code calls generally best practice.
A judge prompt for a support-reply faithfulness check might read:
You are grading a customer-support reply.
Ticket:
<ticket>{ticket}</ticket>
Reply:
<reply>{reply}</reply>
Rules:
- FAIL if the reply states any fact (price, date, policy, product feature)
that does not appear in the ticket or the policy text below.
- FAIL if the reply does not address the customer's main question.
- Otherwise PASS.
Policy text:
<policy>{policy}</policy>
Think through each rule, then output one final line: PASS or FAIL.
Known biases of LLM judges
Zheng et al. (2023), a widely cited study of LLM judges, found that strong judges reached "over 80% agreement" with human preferences, the same level at which humans agree with each other. The same paper documents biases you need to design around:
- Position bias: in pairwise comparisons the judge favours the answer in a particular position. Run each pair twice with the order swapped, and count a win only if it holds both ways.
- Verbosity bias: longer answers get rated higher. Put length expectations in the rubric, or control for length when comparing.
- Self-enhancement bias: a model tends to rate answers like its own more favourably.
- Limited reasoning: judges can be wrong on maths and logic they would need to solve themselves. Give them the reference answer instead of asking them to work it out.
OpenAI's guide adds that LLMs are "better at discriminating between options", so pairwise comparison or pass/fail is more reliable than an absolute score.
Step 5: Check the judge against humans
An unvalidated judge is just another model output. Hand-label 50 to 100 cases yourself (or with a domain expert), run the judge on the same cases, and measure how often it agrees with you. Look hardest at disagreements: they show where the rubric is ambiguous. OpenAI's advice is to scale up only once the judge "consistently agrees with human annotations". Re-check whenever you change the judge prompt or the judge model.
Step 6: Run evals on every change
- Keep the test set fixed while comparing two versions, and version it like code.
- Run each case more than once if production uses a temperature above 0, and report the pass rate across runs.
- Report per category (normal, edge, adversarial) as well as the overall score; an improvement on easy cases can hide a regression on hard ones.
- Track cost and latency alongside quality. A prompt that gains two points but doubles token usage may not be worth it.
- Add every production failure to the set once it's fixed.
Evaluation is also how you measure hallucination in your own application rather than in general; see why AI hallucinates for the failure patterns worth writing test cases for, and how to write a good prompt for the changes you'll be testing.
Frequently asked questions
- How many test cases do I need to evaluate an LLM?
- Enough that a change in score is bigger than the noise. With 10 cases, a 90% pass rate has a 95% interval of roughly 60% to 98%; with 200 cases it narrows to about 85% to 93%. Start with 20 to 50 real examples to find failures, then grow the set toward a few hundred for decisions such as switching models.
- Can I use the same model to judge its own output?
- You can, but it is better not to. Anthropic's example code notes that it is generally best practice to evaluate with a different model from the one that generated the output, and research on LLM judges reports a self-enhancement bias, where a model tends to favour answers like its own.
- What is the difference between an eval and a benchmark?
- A benchmark is a fixed public test set, such as a multiple-choice exam, used to compare models in general. An eval is your own test set built from your task's real inputs and your definition of a good answer. Benchmarks help shortlist models; only your eval tells you whether a model and prompt work for your product.
- Should I evaluate at temperature 0?
- Evaluate with the settings you use in production. If production samples at a higher temperature, run each case several times and report the pass rate across runs, because a single run hides how often the model fails on the same input.