Eval-driven development

In one sentence

Write the evals before or with the feature, like TDD: the eval suite is the spec, and every prompt, model or retrieval change ships only if the suite's numbers say it's better.

Analogy: A pilot's checklist that grows after every incident report. Nobody debates whether the new plane "feels safer": it passes every item the old incidents taught us, or it doesn't fly.

The flywheel: every production failure becomes a permanent regression case, and every change must pass the whole suite before it ships.

How it works

  • Outputs are fuzzy, so you track pass rates per failure mode and need enough cases to beat the noise.
  • The flywheel: ship with tracing, read traces for failures, turn each failure mode into cases plus a grader.
  • Grade with code first; add an LLM judge only where code can't decide.
  • A fix ships when its target metric rises and nothing else drops; its cases join the CI regression suite.
  • Models are replaced every few months; the eval suite is the durable asset that makes switching an afternoon's measurement.

Check yourself

Answer to mark it learned; your answers aren't scored.

One PR rewrites the prompt, swaps the model and adds a reranker. The suite average rises 3 points, but the date-handling failure mode drops 12. What should you do first?

Go deeper

Full explanation

Eval-driven development (EDD) puts the eval suite first: before (or while) you build an LLM feature, you write down the cases it must handle and how each one is graded. The suite is the spec, the way tests are in TDD. Any change — prompt, model, retrieval, tool schema — is measured against it before it ships.

The difference from TDD: outputs are fuzzy and stochastic, so you track pass rates per failure mode, not green/red, and you need enough cases for a difference to beat the noise.

The loop, popularized by Hamel Husain and Eugene Yan, is a flywheel:

  1. Ship to a few users with tracing on (LLM observability & tracing).
  2. Read traces and find failures (Error analysis: look at your data).
  3. Turn each failure mode into eval cases plus a grader: code first (Code-based graders & assertions), LLM-as-a-judge only where needed.
  4. Fix; confirm the targeted metric rises and nothing else drops.
  5. The cases join the regression suite in CI (Evals in CI/CD & release gates).

Hamel's three levels: cheap assertions on every commit, human and model review on a cadence, A/B tests for big changes.

Why an architect cares: models are rented and replaced every few months; the eval suite is the durable asset. With it, moving to a cheaper or newer model is an afternoon of measurement instead of a month of vibes.

Code A minimal eval gate: pass rate per failure mode vs. baseline
pythonA minimal eval gate: pass rate per failure mode vs. baseline
import json, re
from collections import defaultdict

# Each case names the failure mode it guards and how it is graded, e.g.
# {"id": "tz-017", "mode": "wrong_timezone", "input": "...", "check": "regex", "expect": "15:00 CET"}
CASES = [json.loads(line) for line in open("evals/cases.jsonl")]

GRADERS = {
    "contains": lambda out, exp: exp.lower() in out.lower(),
    "regex": lambda out, exp: re.search(exp, out) is not None,
}

def run_suite(generate) -> dict[str, float]:
    passed, total = defaultdict(int), defaultdict(int)
    for c in CASES:
        out = generate(c["input"])  # prompt + model + retrieval under test
        total[c["mode"]] += 1
        passed[c["mode"]] += GRADERS[c["check"]](out, c["expect"])
    return {m: passed[m] / total[m] for m in total}  # never one blended average

baseline = json.load(open("evals/baseline.json"))  # scores of what runs in prod today
candidate = run_suite(new_pipeline)

TOLERANCE = 0.05  # size it to the noise at your n, or re-run flaky cases
regressions = {m: (baseline[m], s) for m, s in candidate.items()
               if m in baseline and s < baseline[m] - TOLERANCE}
assert not regressions, f"Blocked, modes got worse: {regressions}"
Real example

A travel-booking assistant starts with 60 cases written from the spec and 40 from week-one beta traces. Error analysis shows "wrong time zone" in 18% of failing traces, so the team adds 25 cases with a regex grader on the converted time. A prompt fix takes that mode from 52% to 96%, but the suite also shows refund-policy answers dropping from 91% to 78%: the fix had crowded out the policy instructions. Without the suite, that regression ships. Months later a new model arrives; the suite, now 480 cases, shows +4 points at lower cost in one afternoon, so they switch.

Trade-offs +3 · −3

+ You gain

  • Turns "it feels better" debates into a number per failure mode.
  • Model upgrades and cost-down swaps become a same-day measurement.
  • Fixed bugs stay fixed: every failure becomes a permanent regression case.

− You pay

  • Upfront cost: cases, graders and a harness before the feature even demos.
  • Suites get overfit: tuning hard against 200 cases can hide regressions on real traffic.
  • LLM-judged cases add cost, latency and their own noise to every run.

Use it when

Any LLM feature that will outlive a demo: several people change prompts, you expect to swap models, or a regression would reach customers. Start the day you have a first prototype.

Avoid it when

Throwaway prototypes and one-off scripts. And don't build a big generic suite up front: write cases for failures you have actually seen, not ones you imagine.

Numbers to know 3
  • Rule of thumb: start with ~20–50 cases drawn from real failures; hundreds come later, from production traces.
  • Noise floor: at n=100 and an 80% pass rate, the 95% CI is ~±8 points; at n=1,000, ~±2.5.
  • Hamel Husain's three levels: assertions on every commit → human + model eval on a cadence → A/B tests for big changes.
Common pitfalls 4
  • Writing evals after launch, from imagination: you test the failures you guessed, not the ones users hit.
  • One aggregate score: a +2 average can hide one failure mode falling from 95% to 60%.
  • A suite that always passes has stopped finding bugs: keep adding harder cases from production.
  • Changing prompt, model and retrieval at once: the suite says something moved, not what.
Interview questions 2

Answer out loud first, then reveal.

How is eval-driven development different from TDD?Show answer

Same discipline, different math. In TDD a test is deterministic and binary; here outputs are stochastic and often fuzzy, so each failure mode is a pass rate, not a green tick. That means I need enough cases to beat noise: at 100 cases, a 5-point move sits inside the error bar, so I re-run flaky cases and compare per mode. The other difference is where cases come from. TDD writes them from the spec; I seed from the spec, but most cases end up coming from reading production traces.

Leadership wants to switch to a newer, cheaper model. How do you decide?Show answer

I run the candidate on our eval suite and compare per failure mode and per slice, not just the average, plus cost and p95 latency on the same cases. If it's within noise everywhere and cheaper, I ship it behind a flag with a small rollout and watch online metrics. If one slice drops, say non-English or tool calling, I either fix the prompt for that slice or route those requests to the old model. Without a suite this is a month of vibes; with one it's an afternoon. That's the real return on building it.