← Agent Ops & Governance
20 min

Evaluation in Production

The eval pyramid, datasets from production failures, LLM-judge calibration, CI gates and online evaluation.

Lesson 3 of 10
0 done
In plain English

Evals are tests for AI. Start with simple automatic checks, add a set of realistic examples, and use another AI as a judge only with clear rules. Run the tests before every change, and check real results, not just the wording of the answer.

Golden dataset
A set of example inputs with known good outcomes.
LLM judge
An AI that grades another AI's answers.
CI gate
An automatic check that blocks a change if tests fail.
Picture it
Tests for AI, from simple to rich
Simple automatic checks
Right format, allowed values
A set of realistic examples
Cases from real use
AI as a judge, with clear rules
Only with a written rubric
Run before every change
Check real results, not just the wording

Observability tells you what happened. Evaluation tells you whether it was good, and whether your next change will make things better or worse. Teams without evals steer by stories. Someone tries three prompts, the fix seems fine, and a week later something else is quietly broken. Evals are the unit tests of agent building. They are the biggest single difference between Level 1 and Level 2.

The eval pyramid

  • Base, code checks. Is the schema valid? Are the required fields there? Do the tests pass? Do forbidden words stay out? Was the tool called with valid inputs? Did the state change as expected? These checks are cheap and fast, and they run on everything.
  • Middle, scenario tests: a chosen set of realistic inputs with expected results or checklists, run on every change.
  • AI as judge: a model grades outputs against a written rubric. It scales, but it must be checked against people.
  • Top, human review: expert spot-checks, review queues and regular audits. This is expensive and authoritative. It is the source of truth for checking everything below it.

Where test sets come from

Start with 20 to 50 cases that you write by hand from real user needs, including the awkward ones. Then let live use feed you. Every bad trace becomes a new case. That includes a thumbs-down, an escalation, a human correction or an incident. Include the boring happy paths too. A set made only of failures will make every change look like a regression. Tag each case with its type and difficulty, so you can see which slice moved.

Grade outcomes, not only text

For agents that take actions, the final text is the least important result. Did the ticket really get the right status? Was the refund issued exactly once, for the right amount? Check the end state of the world, such as database rows, files and API calls made, against what should have happened. Also grade the path when it matters. Did it use only the allowed tools, stay within budget and ask for approval when it had to?

Measure consistency, not just one pass

Agents are not predictable, so run each case several times. It can solve it sometimes is pass@k: it succeeds at least once in k tries. That is a very different claim from it solves it every time, where all k tries succeed. Customer-facing agents live or die by the second claim. Report both, along with the spread. Treat a case that passes 3 times out of 5 as a failing case with a flaky cause to investigate.

AI judges: powerful and slippery

  • Write a rubric with concrete criteria that are scored separately. Do not write rate the quality.
  • Ask for the reasoning before the score, and keep scales small, such as pass or fail, or 1 to 5.
  • Use a different model as judge, often a stronger one, than the model being tested. This reduces bias towards its own style.
  • Watch out for known biases: a liking for longer answers, for the first option and for its own style.
  • Calibrate. Have people label a sample, measure how often they agree with the judge, and check again from time to time.
judge-rubric.txt
You are grading an AI support agent's reply. Score each criterion 0 or 1 and explain briefly BEFORE scoring.

1. ACCURACY      - every factual claim is supported by the provided knowledge-base excerpts.
2. COMPLETENESS  - it answers every question the customer asked.
3. POLICY        - it did not promise refunds/credits outside policy P-12.
4. TONE          - professional, no blame, no jargon.
5. ACTION        - if an action was needed it chose the correct tool with correct arguments.

Return JSON: {"reasoning": "...", "accuracy":0|1, "completeness":0|1, "policy":0|1, "tone":0|1, "action":0|1}

Evals as a release gate

ci-eval-gate.py
import json, sys

BASELINE = json.load(open("evals/baseline.json"))     # last released scores
results  = run_eval_suite(cases="evals/cases.jsonl", trials=3)

failures = []
if results["task_success"] < BASELINE["task_success"] - 0.02:
    failures.append(f"task_success regressed: {results['task_success']:.1%}")
if results["policy_violations"] > 0:
    failures.append("policy violations must be zero")
if results["cost_per_success"] > BASELINE["cost_per_success"] * 1.25:
    failures.append("cost per success up >25%")

if failures:
    print("EVAL GATE FAILED\n- " + "\n- ".join(failures)); sys.exit(1)
print("eval gate passed")

Online evaluation

  • Sample live traffic and run judges in the background, to track quality over time and catch drift.
  • Shadow mode: run a new version on real inputs without showing its output, then compare.
  • Canary and A/B: send a small share of traffic to the new version and compare the outcome numbers.
  • Quiet signals: retries, rewording, giving up, human overrides and escalations. They are noisy, but there are plenty of them.
Key takeaways
  • ✓Layer your evals: code checks, scenario sets, calibrated AI judges and human review.
  • ✓Grow the set from live failures, and keep the happy paths.
  • ✓Grade end-state outcomes and run several tries. Being consistent matters more than a lucky pass.
  • ✓Make evals a release gate with clear limits for quality, safety and cost. Extend them to live traffic with shadow and canary runs.
Hands-on exercise

Build a 25-case regression suite

  1. Write 25 test cases for one agent: 15 typical, 5 edge cases and 5 hostile or policy-sensitive ones.
  2. Add code checks first, such as schema, forbidden content and the right tool called, before any AI judging.
  3. Write a judge rubric with four criteria. Have a person label 10 outputs and compare their labels with the judge's.
  4. Run the suite three times. Record the pass rate and how flaky it is, and set a gate threshold you could defend.
Check yourself
Q1What is the difference between pass@k and requiring all k tries to pass? Which matters for customer-facing agents?show answer

pass@k asks whether at least one of k tries succeeds, which shows what the agent can do. All-k asks whether it succeeds every time, which shows how dependable it is. Customer-facing agents need the second.

Q2Why use a different model as judge from the one under test?show answer

Models tend to favor their own style and reasoning, so a judge from the same model gives inflated scores. A different, often stronger, judge reduces that bias.

Q3Your test set holds only past failures. What is the risk?show answer

Every change will look like a regression, because the happy paths are not protected. You cannot tell whether you broke something that used to work. Include typical cases too.

← Observability & TracingGuardrails & Agent Security →
0 / 10 finished0%