AI-native engineering · L2Evals for LLM systems

Evals for LLM systems

Test LLM features with a fixed set of cases, a grader and a score, and run it on every prompt or model change.

L2 SeniorAI-native engineering19 min read
Fact-checked by AI against cited sources · Human review pendingLast reviewed 22 Oct 2026 · How we check content
AI tools change fast: we review this lesson every quarter (next by 20 Jan 2027).
Section 1 of 8

What broke

On 25 April 2025, OpenAI finished rolling out an update to GPT-4o in ChatGPT. It made the model "noticeably more sycophantic". It aimed to please users: it validated doubts, fuelled anger and urged impulsive actions. 6

The update combined several changes that each looked good on its own. One was a new reward signal from users' thumbs-up and thumbs-down clicks. OpenAI believes that, together, these changes weakened the signal that had kept sycophancy in check. 6

Why did the checks miss it? The offline evals "generally looked good". Users in a small A/B test seemed to like the model. There were no deployment evals that tracked sycophancy. Some expert testers said the model "felt" slightly off, but OpenAI launched anyway. It later called this "the wrong call". 6

OpenAI began the rollback on 28 April. It is adding sycophancy evals to its deployment process. Behaviour issues now block a launch, even when A/B tests look good. It also plans to value hands-on testing more. 6 It is expanding its evals to find issues beyond sycophancy. 7

The lesson for you: an eval set only catches what it tests. A good score says nothing about a failure that has no test case.

Section 2 of 8

The idea in simple words

Normal unit tests compare output with one expected value. That works when code is deterministic: the same input always gives the same output. LLM features are different in two ways.

  • The output changes between runs. Anthropic runs several trials of each task "because model outputs vary between runs". 2
  • There are many correct answers. "Delivery takes 3 to 5 days" and "You will get it in 3 to 5 working days" are both right. A test that checks for one exact string fails on the other.

OpenAI's guide says this variability makes traditional software testing methods not enough on their own. 3

An eval fixes this with three parts:

  1. A test set. Saved inputs, each with a note about what a good answer must do.
  2. A grader. Logic that scores one output. 2 It can be code, a model or a person.
  3. A score you track. For example, 37 of 40 cases pass. You compare it with the last good version, the baseline.

The key idea. An eval is a unit test for an LLM feature. It does not ask "is this output equal to X?". It asks "does this output meet our rules?", over many cases, every time you change something.

Section 3 of 8

How it works

Step through one prompt change with Next and Back. The support bot in this example is made up.

A prompt change goes through the eval set before it shipsSupport bot · prompt v7 + “Always give a direct answer.” run in CIEval set · 40 casesreal tickets · edge cases · attacks gradecode checksmodel grader baseline v6: 37 / 40 → v7: 34 / 40 4 “I don't know” cases now invent a rulemerge blocked fix, run againv8: 38 / 40 · cost and latency same ✓ ship to 5% of usersgrade a sample of live answers SeniorPath
  1. You add one line to a support bot's prompt to fix a customer complaint. Trying three examples by hand is not enough. The change must pass the eval set first.
  2. The CI job runs the new prompt on all 40 saved test cases. They are real tickets, edge cases, and a few prompt injection attacks.
  3. Graders score every output. Code checks test the format and banned words. A model grader with a rubric checks if the answer is correct and grounded.
  4. The job compares the new score with the baseline, the score of the prompt that is live now. The total went down from 37 to 34.
  5. The diff by case shows the problem: one case was fixed, but four cases that should say "I don't know" now invent a policy. The job blocks the merge.
  6. You change the line to "Give a direct answer when the sources cover the question." You run the set again. The score is 38, and cost and latency did not change.
  7. The change ships to a small share of users first. A sample of live answers is graded every day, so new kinds of failure show up as new test cases.
Step 1 of 7

Build the test set

Start small. Anthropic says 20 to 50 simple tasks drawn from real failures is a great start. 2 Turn bug reports and the checks you already do by hand into test cases. 2 Mix three kinds of cases:

  • Real user cases. Take them from logs and support tickets. OpenAI advises you to log as you build, so you can mine the logs for good eval cases. 3 The set should look like your real traffic. 1
  • Edge cases. Anthropic lists missing or irrelevant input, very long input, harmful user input, and cases where even humans would disagree. 1 Add questions where the right answer is "I don't know".
  • Adversarial cases. Inputs that try to break the feature on purpose. See the safety section below.

Write down what "good" means for each case. Vague cases give noisy scores: "Ambiguity in task specifications becomes noise in metrics". 2 If a case fails every time, check the case first. Anthropic says a 0% pass rate is most often a sign of a broken task. 2

Choose graders

Anthropic's advice is to choose the fastest, most reliable and most scalable method that works for each check. 1

  • Code checks. Exact match, "contains this phrase", valid JSON, length limits. They are the fastest and most reliable, but lack nuance for complex judgments. 1 Hamel Husain runs these assertions on every code change. 5
  • Reference comparison. Compare the output with a saved good answer, for example with ROUGE-L for summaries. 1
  • Model graders (LLM-as-judge). A second model reads the output and grades it against a rubric. It is fast, flexible and suits complex judgment, but test it for reliability before you scale it. 1 Give it a detailed rubric, ask for a simple result such as "correct" or "incorrect", and let it reason before it scores. 1 Anthropic's examples say it is generally best to use a different model from the one that wrote the output. 1
  • Human review. The most flexible and highest quality, but slow and expensive. 1 Anthropic advises avoiding it where possible. 1 Save systematic human studies for calibrating model graders. 2

Know the biases of model graders

Zheng et al. studied strong models as judges. They report position bias (favouring an answer because of its place in the list), verbosity bias (favouring longer answers) and self-enhancement bias (maybe favouring its own answers; their data could not confirm this one). 4 In one test with two similar answers to each MT-Bench question, GPT-4 gave the same verdict in both orders only 65% of the time. 4 Their fix: ask twice with the order swapped, and count a tie when the verdicts disagree. 4

Still, on their MT-Bench data, GPT-4's pairwise verdicts agreed with human experts 85% of the time, on votes that were not ties. Two humans agreed 81% of the time. 4 But that is their benchmark, not your feature. Hamel Husain advises you to track how well your model grader matches human judgment. 5

Offline evals, online monitoring and A/B tests

An offline eval runs on saved cases before you ship. It cannot show what real users will do. Use three layers:

  • Offline evals on every change. 2
  • Production monitoring after launch, for the truth about real behaviour. 2 Read real user traces, and sample more as volume grows. 5
  • A/B tests for big changes, once you have enough traffic. 2 They cost the most, so run them the least often. 5

Regression evals in CI

Anthropic separates two kinds of evals. Capability evals measure what the feature cannot do yet, so they start with a low pass rate. Regression evals check that old tasks still work, and should have a nearly 100% pass rate. 2

Our advice: run the regression set in CI for every change to the prompt, the model version, the retrieval settings or the tools. Show the result case by case, not only the total. A total of 34 can hide four new failures behind one new fix. Block the merge when a case that passed before now fails.

Measure cost and latency too

Anthropic lists latency and price as success criteria. 1 Latency, token usage and cost per task can be tracked on the same fixed set of tasks. 2 A new model that scores 2% higher but doubles your cost may be the wrong choice.

Do not overfit the test set

If you tune a prompt against the same 40 cases for months, the score can go up while real users see no change. This is overfitting. Our advice:

  • Keep a held-out set that you run, but never tune against.
  • Add new cases from live traffic every month.
  • When the set is fully passed, write harder cases. Anthropic says an eval at 100% still tracks regressions but gives no signal for improvement. 2
  • Make graders hard to fool. The feature "shouldn't be able to easily 'cheat' the eval". 2

Safety evals

Add attack cases to the set, and run them like any other test. OWASP advises adversarial testing and attack simulations against prompt injection. 8 Include direct attacks, where the user types the instructions. Include indirect attacks, hidden in a web page or file the model reads. 8 For harmful output, Anthropic gives a measurable example: under 0.1% of outputs flagged for toxicity, out of 10,000 trials. 1 OWASP also advises checking that the output matches the expected format with deterministic code. 8

Section 4 of 8

Trade-offs

This table is our own summary of the cited sources.

GraderSpeed and costHandles many correct answersSame result every runUse it for
Code checksYes Fast and cheap. 1No Too strict for open-ended text.Yes Format, JSON, banned words, required phrases, length.
Model grader (LLM-as-judge)Fast, but costs more than code. 2Yes Good for tone, correctness, grounding.No It varies, and has position and verbosity biases. 4Open-ended answers, once you have checked it against human labels.
Human reviewNo Slow and expensive. 1Yes The highest quality.No Experts can disagree. 3Building the rubric, calibrating graders, reading samples of live traffic.

Simple rule: use code where a rule is exact, a model grader where it needs judgment, and humans to check both.

Section 5 of 8

At work: how a senior uses this

  • Before anyone changes a prompt, ask: "What is our eval set, and what is the baseline score?" If there is none, build 20 to 50 cases first.
  • Turn every bug report about the LLM feature into a test case on the same day.
  • Treat a model upgrade like a dependency upgrade. Run the full set and compare quality, cost and latency before you switch.
  • Sample model-grader results each month and check that they still agree with human labels.
  • Ship big changes behind a feature flag to a small share of users, and watch live metrics. See Safe deploys.
Section 6 of 8

With AI

What to ask the agent

"Here are 30 real support tickets. For each one, write what a good answer must include and must not include. Mark tickets where the right answer is 'I don't know'."

"Write a script that runs our prompt on every case in evals/cases.jsonl, applies these code checks, and prints a table of cases that passed before and fail now."

What to check yourself

  • The expected behaviour for each case is right. The agent may guess the policy, so check a sample by hand.
  • The model grader agrees with your own labels on at least 20 cases before you trust it.
  • The CI job compares per case with the baseline, and fails the build on a new regression.
  • You never put held-out cases into a prompt you are tuning.
Section 7 of 8

Check yourself

1. You changed one line in the prompt. You tried the three examples from the bug report, and all three look better. What should you do before you merge?

Show answer

Run the full eval set and compare the score per case with the baseline. A prompt change can fix one case and break others. Only the full set, compared case by case with the baseline, shows what else changed.

2. Your feature must return valid JSON with a "category" field from a fixed list. Which grader fits best?

Show answer

A code check that parses the JSON and checks the field. The rule is exact, so code can check it. Code checks are fast, cheap and give the same result every time.

3. Your model grader compares answer A with answer B, and it keeps picking the first answer it sees. What is a good fix?

Show answer

Ask twice with the order swapped, and count a win only if both runs agree. This is position bias. Zheng et al. suggest swapping the order and calling it a tie when the two verdicts disagree.

4. For months your team has tuned the prompt against the same 50 cases. The score is now 49 out of 50, but user complaints have not dropped. What is the most likely problem?

Show answer

The prompt is overfitted to the eval set, and the set no longer looks like real traffic. A high score on old cases says little about new ones. Add fresh cases from real traffic and keep some cases you never tune against.

5. Which question can only online monitoring or an A/B test answer, not an offline eval?

Show answer

Do real users finish their task more often with the new version? Offline evals run on saved cases. How real users behave can only be measured with real traffic.

Your progress is saved only in this browser. Export it to keep it safe.

Was this clear?
Report a mistake (opens GitHub in a new tab)
Section 8 of 8

Go deeper

Show 8 sources and related lessons
  1. Anthropic, “Define success criteria and build evaluations”, Claude documentation (opens in a new tab)
    How to write measurable success criteria, which edge cases to include, and when to use code, human or model grading. Read "Grade your evaluations".
  2. Anthropic Engineering, “Demystifying evals for AI agents” (January 2026) (opens in a new tab)
    Words for the parts of an eval, the three grader types, capability and regression evals, and how evals fit with monitoring and A/B tests.
  3. OpenAI, “Evaluation best practices”, API documentation (opens in a new tab)
    A neutral second view. The eval process step by step, judge biases, human calibration and common mistakes.
  4. Zheng et al., “Judging LLM-as-a-Judge with MT-Bench and Chatbot Arena”, NeurIPS 2023 Datasets and Benchmarks (arXiv:2306.05685) (opens in a new tab)
    The main study of model graders. Sections 3.3 and 3.4 cover position, verbosity and self-enhancement bias and how to reduce them.
  5. Hamel Husain, “Your AI Product Needs Evals” (March 2024) (opens in a new tab)
    A practitioner's guide. Cheap assertions first, then human and model review of logged traces, then A/B tests.
  6. OpenAI, “Expanding on what we missed with sycophancy” (2 May 2025) (opens in a new tab)
    The official account of the GPT-4o rollback. How OpenAI reviews models before launch, why its evals missed the problem, and what it changed. Read via web.archive.org because openai.com blocked automated access.
  7. OpenAI, “Sycophancy in GPT-4o: what happened and what we’re doing about it” (29 April 2025) (opens in a new tab)
    The first, shorter post about the rollback and the planned fixes.
  8. OWASP, “LLM01:2025 Prompt Injection”, OWASP Top 10 for LLM Applications 2025 (opens in a new tab)
    Direct and indirect prompt injection, and the advice to run adversarial tests and attack simulations.

Related: LLM fundamentals for product engineers · RAG: retrieval-augmented generation · Guardrails, cost and latency for LLM features (coming soon) · Safe deploys and config changes

Evals for retrieval, such as recall@k, are covered in RAG: retrieval-augmented generation. Safety and cost in production: Guardrails, cost and latency for LLM features.

Term

See full entry

Jump to a section

  1. 1What broke
  2. 2The idea in simple words
  3. 3How it works
  4. 4Trade-offs
  5. 5At work
  6. 6With AI
  7. 7Check yourself
  8. 8Go deeper