CONTENTS
CHAPTER 9

Evals

7 MIN READ

If you take one chapter from this book into your work, make it this one. Every practitioner whose work underlies this book says the same thing in different words: the teams that succeed are the teams that measure. Hamel Husain's 2024 post is titled, simply, "Your AI Product Needs Evals". He and Shreya Shankar report spending 60–80% of their development time on error analysis and evaluation.

Why so much? Because without evals, every change is a guess. You edit a prompt to fix one complaint and silently break three other things. You upgrade the model and can't say whether it's better. You argue about quality in meetings instead of looking at data.

What an eval is

An eval is a repeatable test of your system's behaviour on a set of inputs, producing a score you can track. It has three parts:

  1. A dataset: inputs (and sometimes reference outputs or criteria).
  2. The system under test: your full pipeline, not just the model.
  3. A grader: code, a model, or a human that decides pass or fail.

Husain describes three levels:

  • Level 1: unit tests. Fast, cheap assertions run on every change. Does the output parse? Does it include a citation? Does it avoid mentioning a competitor? Is the SQL valid?
  • Level 2: model and human evaluation. Reviewing traces, labelling them, and using LLM judges calibrated against human labels. Slower; run regularly.
  • Level 3: A/B testing. Real users, real outcomes. For mature products making significant changes.

Start with error analysis, not metrics

The most common mistake is to start by picking metrics: "let's measure helpfulness, coherence and relevance on a 1–5 scale." Husain and Shankar argue strongly against this. Generic metrics measure what's easy to measure, not what's actually going wrong in your product.

Instead, start by looking at your data. Their evals FAQ describes the process, borrowed from qualitative research:

1. Gather traces. Collect around 100 diverse, real (or realistic) interactions with your system: inputs, retrieved context, tool calls, outputs.

2. Open coding. A domain expert reads each trace and writes a free-form note about what went wrong, if anything. Focus on the first failure in each trace, since later problems often cascade from it. Don't use categories yet; just describe. Annotate at least 30 traces yourself before handing anything off.

3. Axial coding. Group the notes into categories: "retrieved the wrong product version", "ignored the user's constraint", "tone too formal", "hallucinated a policy". Count each category. The FAQ calls this the most important step. Keep going through traces until new ones stop revealing new categories (what qualitative researchers call theoretical saturation).

4. Prioritize. Now you have a ranked list of what's actually broken. In Husain's "A Field Guide to Rapidly Improving AI Products" (2025), one client found three issues accounted for over 60% of problems.

5. Build evals for the top failures. Each failure category becomes a targeted eval: a code check if it can be detected mechanically, an LLM judge if it needs judgment.

 traces ─► open coding ─► axial coding ─► counts ─► targeted evals ─► fix ─► re-run
   ▲         (notes)      (categories)   (priority)                           │
   └──────────────────────────── new traces from production ◄─────────────────┘

Husain also recommends building a simple custom viewer for your traces, tailored to your domain, because removing friction from looking at data is what makes people actually do it.

Key insight: You can't write good eval criteria before you've looked at outputs. Shankar and colleagues showed this in "Who Validates the Validators?" (2024): people's criteria change as they grade, a phenomenon they named criteria drift. Evals are discovered, not specified.

Code-based checks

Whenever a failure can be detected deterministically, use code. It's free, fast and never disagrees with itself.

def check_reply(reply, context):
    failures = []
    if not reply.citations:
        failures.append("no_citation")
    for cid in reply.citations:
        if cid not in context.chunk_ids:
            failures.append("cited_unknown_chunk")
    if contains_price(reply.text) and not context.pricing_doc_retrieved:
        failures.append("price_without_source")
    if len(reply.text.split()) > 250:
        failures.append("too_long")
    return failures

Many teams underuse these. What We Learned from a Year of Building with LLMs recommends assertion-based tests built from real production samples, and they're the right first line of defense.

LLM-as-judge, done properly

Some failures need judgment: "did the reply address the user's actual question?" For those, a model can grade outputs, which is called LLM-as-judge. It's powerful and easy to do badly.

The foundational study is Zheng et al., "Judging LLM-as-a-Judge with MT-Bench and Chatbot Arena" (2023). They found strong model judges agreed with human preferences over 80% of the time, about the same as humans agree with each other. They also documented biases you must design around:

  • Position bias: in pairwise comparisons, preferring whichever answer comes first (or second).
  • Verbosity bias: preferring longer answers.
  • Self-enhancement bias: preferring outputs from the same model family.

Husain's guide "Using LLM-as-a-Judge For Evaluation" lays out a process he calls critique shadowing:

  1. Find the principal domain expert.
  2. Build a diverse dataset of real outputs.
  3. Have the expert give pass/fail judgments, each with a written critique explaining why.
  4. Fix obvious errors you find along the way.
  5. Build the judge iteratively, using the expert's critiques as few-shot examples, until its judgments agree with the expert's.
  6. Run error analysis on the judge's results.
  7. Build more specialized judges where needed.

Two design choices matter most:

Binary, not scales. Use pass/fail, not 1–5. As Husain puts it, people don't know what to do with a 3 or a 4. Scales hide disagreement and make thresholds arbitrary. Eugene Yan's review of LLM evaluators reaches a similar view: prefer binary outputs and measure the judge with precision and recall.

One criterion per judge. A judge that checks "is it faithful, helpful, concise and polite" gives you a muddy answer. Four judges, one per failure category from your error analysis, give you four clear ones.

Validate the judge. A judge is itself a model, so it has an accuracy. Measure its agreement with your expert's labels on a held-out set, separately for passes and fails (a judge that passes everything has 95% agreement when 95% of outputs pass, and is useless). Re-check it when you change models.

Concept deep dive: eval scores have error bars

Suppose version A scores 82% on your 100-question eval and version B scores 85%. Is B better?

Probably you can't tell. If each question is a pass/fail trial, the standard error of a pass rate pp on nn questions is approximately:

SE=p(1−p)nSE = \sqrt{\frac{p(1-p)}{n}}

For p=0.85p = 0.85 and n=100n = 100, SE≈0.036SE \approx 0.036, so a 95% confidence interval is about ±7\pm 7 percentage points. A 3-point difference is noise.

Evan Miller's "Adding Error Bars to Evals" (Anthropic, 2024) gives recommendations every team should follow:

  1. Report standard errors using the Central Limit Theorem, as above.
  2. Cluster standard errors when questions come in related groups (several questions about the same document aren't independent).
  3. Reduce variance within questions by sampling each question several times, or using the model's probability of the correct answer.
  4. Analyze paired differences. Both versions answer the same questions, so compare them question by question. Paired comparisons are much more sensitive than comparing two overall scores.
  5. Use power analysis to decide how many questions you need to detect the difference you care about.

The practical upshot: grow your eval sets as your product matures, compare versions on the same questions, and be suspicious of small wins.

Evaluating agents

Agents add two problems.

Reliability across runs. An agent that solves a task once may fail it the next time. The τ-bench benchmark from Sierra (Yao et al., 2024) introduced pass^k: the probability that all kk independent attempts succeed. Contrast with pass@k, the probability that at least one succeeds, which is the right metric for "generate several options and pick one" but the wrong one for a customer-facing agent that must succeed every time. In τ-bench's retail domain, a strong model's pass^8 was under 25%, far below its single-try success rate. If your agent will handle the same kind of request thousands of times, pass^k is the number that matters.

Grade outcomes, not paths. Agents can reach the right result by many routes. τ-bench grades by comparing the final database state to the goal state. Anthropic's research system post gives the same advice: judge end states, not whether the agent followed your expected steps. Still read the paths during error analysis, because inefficient or risky paths are failures too.

Anthropic also recommends starting small. They began their research system evals with about 20 queries representing real usage, because early changes have large effects that even small sets reveal.

Evals in the development loop

Put evals where they change behaviour:

  • On every change (CI): unit checks and a small, fast eval set. Block merges that regress.
  • Before releases and model upgrades: the full eval suite, with paired comparisons and error bars.
  • In production: sample live traffic, run judges and checks on it, and feed failures back into error analysis.
  • Pin model versions. Use dated model identifiers, not floating aliases, so the model doesn't change underneath your evals.

Key takeaways

  • Evals are the core skill of AI engineering. Without them, every change is a guess.
  • Start with error analysis on real traces: open coding, then axial coding, then counts. Build evals for the top failure categories.
  • Use code checks wherever possible. Use LLM judges for judgment calls: binary, one criterion each, calibrated against an expert with critique shadowing.
  • Eval scores have error bars. Use paired comparisons and enough questions.
  • For agents, measure pass^k and grade end states.

Exercises

  1. Collect 30 traces from an AI feature you own (or generate them). Do open coding and axial coding. What are your top three failure categories?
  2. Write an LLM judge for one category. Label 40 outputs yourself, then measure the judge's agreement separately on passes and fails.
  3. Your eval has 200 questions. Version A passes 160, version B passes 170. Compute the standard errors. Then explain what extra information a paired analysis would need.