Lesson 2's graders can't tell whether a reply answers the question or promises something it shouldn't. This lesson hands that criterion to an LLM judge. Before you let the judge grade the drafter, you measure the judge itself, against 60 replies whose correct verdict you already know.
By the end you will be able to:
- build a one-criterion PASS/FAIL judge with structured output;
- calibrate it against labels known by construction, with FAIL as the positive class;
- read TPR, TNR and Cohen's kappa, and say why raw agreement hides which way a judge errs;
- sharpen an ambiguous criterion and measure again;
- choose between
claude-haiku-5-5andclaude-sonnet-5-5as the judge on errors and cost.
Before you start. You need Lesson 2. Then:
cd tutorials-code/build-an-llm-eval-suite/02-judging/03-an-llm-judge-you-can-trust
uv sync
uv run python calibrate.py # replays the recorded calibration; no key
uv run pytest tests # 33 passedThe replay prints four lines, one per judge and criterion, starting with v1 claude-haiku-5-5 TPR 1.00 TNR 1.00. As in Lesson 2, it answers from runs/calls.jsonl, the real calls recorded once with --live --record; only a new recording needs ANTHROPIC_API_KEY.
The companion folder is Lesson 2's code plus evals/judge.py, evals/metrics.py, evals/calibration.py, the calibration set and the recorded judge runs, plus judge_one.py, with 33 tests. Every number below comes from it. The judge runs were recorded on 2026-11-21, with effort low.
1. A judge for one criterion
An LLM judge is a model call that returns a verdict on exactly one criterion. Its output is a PASS or FAIL, nothing else. It goes through Lesson 2's complete(), which sends the schema in output_config.format, sets effort to low, and marks the system prompt with cache_control so it is cached:
CRITERIA = {
# The first wording.
"v1": (
"The reply answers the question the ticket asked, and promises nothing "
"the knowledge base doesn't support."
),
# The second wording, added after the first calibration (see below).
"v2": (
"The reply answers the question the ticket asked, and promises nothing "
"the knowledge base doesn't support. A reply that says the ticket has been "
"passed to another team passes without answering the question itself, "
"as long as it doesn't attempt an answer the knowledge base doesn't support."
),
}
VERDICT_SCHEMA = {
"type": "object",
"properties": {"verdict": {"type": "string", "enum": ["PASS", "FAIL"]}},
"required": ["verdict"],
"additionalProperties": False,
}
def judge_system(criterion: str, kb: dict[str, Article]) -> str:
return (
"You grade draft replies written by Helpline's support assistant.\n\n"
f"Criterion: {CRITERIA[criterion]}\n"
"Answer PASS if the reply meets the criterion, FAIL if it doesn't.\n\n"
f"Knowledge base:\n\n{kb_text(kb)}"
)
def judge(
model: Model,
ticket: str,
reply: str,
kb: dict[str, Article],
criterion: str = "v2",
repeat: int = 0,
) -> tuple[str | None, Completion]:
"""Return ("PASS" | "FAIL" | None, the completion). None means no usable verdict."""
c = model.complete(
judge_system(criterion, kb),
judge_user(ticket, reply),
VERDICT_SCHEMA,
tag=f"repeat={repeat}",
)
# Structured output doesn't guarantee an enum's capitalization: compare case-insensitively.
verdict = str((c.value or {}).get("verdict", "")).upper()
return (verdict if verdict in ("PASS", "FAIL") else None), cThe knowledge base and the criterion are in the system prompt, which is cached; the ticket and the reply are the user turn. The judge sees only the reply's text, not the drafter's escalate flag. Lesson 2's code graders already check that flag.
Two details come from the structured outputs documentation. Enum values can come back with different capitalization, so the verdict is upper-cased before it's compared. And complete() checks stop_reason before parsing, so a refusal or a cut-off response reaches judge() as no value and comes back as None. The calibration counts a None as FAIL, the cautious side, before the vote. That choice has a cost: a refusal on a defective reply would count as a catch and flatter TPR. So the report also counts no_verdict separately. It was 0 in every recorded run; if yours isn't, look at those replies before you read TPR.
The schema has no reason field on purpose. In the AI Lab's llm-judge-calibration-benchmark, which used the same two models on 2026-11-21, asking for a critique before the verdict made Haiku 5.5 fail 65% of the correct escalation replies. When you need a reason to debug a disagreement, ask for it in a separate call.
2. Labels known by construction
To measure a judge you need replies whose correct verdict you already know. In a product, two people label a sample independently, you check how often they agree, and you resolve the disagreements. This tutorial needs labels that anyone can reproduce, so it builds them instead:
- 30 reference replies, written from the knowledge base to meet the criterion, for 30 golden cases: 20 answers and 10 escalations. Each is labelled PASS.
- 30 copies with one planted defect, each labelled FAIL: 12 unsafe promises, 7 wrong numbers, 7 that answer a different question, and 4 that don't answer at all.
These are labels known by construction: the label follows from how each reply was made. Nobody voted on them. Two from the set, both for the G35 outage ticket:
{"id": "L55", "case_id": "G35", "label": "PASS",
"reply": "Sorry for the disruption. I've passed this to our engineering team as an active incident. You can follow updates on status.helpline.example."}
{"id": "L56", "case_id": "G35", "label": "FAIL", "defect": "unsafe_promise",
"reply": "Sorry for the disruption. Engineering will have this fixed within 30 minutes."}scripts/build_labels.py turns data/reference_replies.json into data/labels.json, so you can read both versions side by side.
3. Reading a judge: FAIL is the positive class
At a gate, a judge's job is to catch failures. So FAIL is the positive class: a true positive is the judge saying FAIL on a reply labelled FAIL.
@dataclass(frozen=True)
class Confusion:
tp: int # label FAIL, judge FAIL
fn: int # label FAIL, judge PASS
fp: int # label PASS, judge FAIL
tn: int # label PASS, judge PASS
@property
def tpr(self) -> float:
return self.tp / (self.tp + self.fn) if self.tp + self.fn else float("nan")
@property
def tnr(self) -> float:
return self.tn / (self.tn + self.fp) if self.tn + self.fp else float("nan")- TPR, the true positive rate, is the share of bad replies the judge fails: its catch rate.
- TNR, the true negative rate, measures the other direction: how many good replies the judge passes.
- Raw agreement counts the verdicts that match their label, over all 60.
- Cohen's kappa is agreement after removing the agreement two coin-flippers with the same PASS/FAIL rates would reach by chance: κ = (observed − chance) / (1 − chance). Like raw agreement, it is one number. It hides the direction of the errors too, which is why TPR and TNR come first.
calibrate.py runs each judge three times per reply and takes the majority verdict. With three votes there can't be a tie; majority() sends a tie to FAIL for when you choose an even number. Every number in the tables below is a majority result. To see one reply's three votes, use judge_one.py:
$ uv run python judge_one.py L57 --model claude-sonnet-5-5 --criterion v1
L57 (G37: SCIM provisioning)
reply: I've passed your question about SCIM provisioning to our product team, who will reply on this ticket.
label PASS; claude-sonnet-5-5, criterion v1: ['FAIL', 'FAIL', 'FAIL'] -> FAIL4. The first criterion, and a judge that errs one way
uv run python calibrate.py --criterion v1 replays criterion v1 alone. With v1, after the one label fix described below:
v1 claude-haiku-5-5 TPR 1.00 TNR 1.00 agreement 1.00 kappa 1.00 escalation replies passed 10/10 $0.0061
v1 claude-sonnet-5-5 TPR 1.00 TNR 0.77 agreement 0.88 kappa 0.77 escalation replies passed 3/10 $0.0999Sonnet's confusion matrix is 30 true positives, 0 false negatives, 7 false positives and 23 true negatives. Raw agreement is 53 of 60, or 88%, which sounds respectable. Kappa shows how much of that is above chance. The labels are half FAIL, and Sonnet said FAIL 37 times out of 60, so chance agreement is 0.5 × 37/60 + 0.5 × 23/60 = 0.5. That gives κ = (0.883 − 0.5) / (1 − 0.5) = 0.77. It hides that every one of Sonnet's errors went the same way: it failed 7 good replies and missed no bad ones.
And the 7 aren't random. All of them are escalation replies, such as L57: "I've passed your question about SCIM provisioning to our product team, who will reply on this ticket." Sonnet passed only 3 of the 10. Read the criterion again: "The reply answers the question the ticket asked." An escalation reply, by design, doesn't answer it. Sonnet read v1 literally, and literally it is right. The criterion was ambiguous; the labels assumed one reading, Sonnet took the other.
This is what calibration is for. A judge that fails every escalation reply would, at a gate, punish the drafter for doing the right thing on 15 of the 40 golden cases.
5. Sharpening the criterion
Criterion v2 adds one sentence: a reply that says the ticket has been passed to another team passes without answering the question, as long as it doesn't attempt an unsupported answer. uv run python judge_one.py L57 --model claude-sonnet-5-5 now ends -> PASS. Measured again:
v2 claude-haiku-5-5 TPR 1.00 TNR 1.00 agreement 1.00 kappa 1.00 escalation replies passed 10/10 $0.0062
v2 claude-sonnet-5-5 TPR 1.00 TNR 0.97 agreement 0.98 kappa 0.97 escalation replies passed 9/10 $0.1022| Judge | Criterion | TP | FN | FP | TN | TNR (95% interval) | kappa |
|---|---|---|---|---|---|---|---|
| Haiku | v1 | 30 | 0 | 0 | 30 | 1.00 (0.886–1.0) | 1.00 |
| Sonnet | v1 | 30 | 0 | 7 | 23 | 0.77 (0.591–0.882) | 0.77 |
| Haiku | v2 | 30 | 0 | 0 | 30 | 1.00 (0.886–1.0) | 1.00 |
| Sonnet | v2 | 30 | 0 | 1 | 29 | 0.97 (0.833–0.994) | 0.97 |
Sonnet still fails one good reply, L55, the outage reply shown earlier. Read it and decide: you can sharpen the criterion again, or accept the error and record it. Don't rewrite a label to match the judge. If you find that a reply itself is wrong, fix the reply so its label is true again, as the next section shows.
Two cautions about v2. It was written after reading these 60 verdicts and then measured on the same 60, so its numbers are optimistic. A fresh set of labelled replies is the honest test. And the new sentence opens a door: a reply that only says "I've passed this on" now passes the judge even on a ticket the knowledge base answers. The judge can't see that. Lesson 2's escalation_correct can, because it compares the draft's escalate flag with the expected one. The judge and the code graders cover for each other.
The intervals matter. With 30 good replies, a TNR of 1.00 means "at least 0.886, probably". It doesn't mean "never wrong".
6. When the judge was right and the label was wrong
On the first calibration run, Sonnet also failed the reference reply for G26, the credit request. It was:
I'm sorry about the disruption last Tuesday. I've passed your credit request to our billing team, who handle SLA claims and will follow up on this ticket.
KB-109 says: "Service credits are defined in the Enterprise SLA. If monthly uptime falls below 99.9%, the account owner can request a credit under Billing > SLA claims within 30 days of the incident. Support agents cannot grant or promise credits." Read against it, that reply makes two promises the knowledge base doesn't support. The article never says billing handles SLA claims: it says the account owner files them under Billing > SLA claims. And it tells the customer to wait for billing to sort out a credit, when the knowledge base says the customer's own account owner has to claim it within 30 days. Saying the ticket was passed on is fine, as L57 does. Misdescribing who does what about a credit is not. Haiku also failed this reply under criterion v1. The "reference" reply broke the criterion it was meant to illustrate.
So the fix was the reply, not the label or the judge. The new reference points the customer to the self-serve claim and says the ticket was passed to billing:
I'm sorry about the disruption last Tuesday. Support can't grant credits, but your account owner can request one under Billing > SLA claims within 30 days of the incident; the Enterprise SLA covers months where uptime fell below 99.9%. I've also passed this ticket to our billing team.
The numbers from before the fix are kept in runs/calibration-before-label-fix.json. Labels made by construction are still made by someone, and calibration checks them as well as the judge.
7. Repeats and a majority vote
Every judge gave the same verdict on all three repeats for every reply: self-consistency was 100% in all four runs. On this set, the majority vote changed nothing, and the repeats tripled what calibration cost. One pass over the 60 replies with criterion v2 costs about $0.0021 with Haiku and $0.034 with Sonnet; three passes cost $0.0062 and $0.1022. That isn't true in general. In the AI Lab benchmark, Haiku 5.5 gave the same verdict on all three repeats for 84–94% of cases and Sonnet 5.5 for 97–100%. Measure your own judge's consistency once. Keep repeats only if it is below what your gate can tolerate.
8. Choosing the judge
| Haiku 5.5 | Sonnet 5.5 | |
|---|---|---|
| TPR / TNR with criterion v2 | 1.00 / 1.00 | 1.00 / 0.97 |
| Cost for 180 judgements (60 replies × 3) | $0.0062 | $0.1022 |
| Cost per judgement | $0.000035 | $0.00057 |
Both judges used almost the same tokens per judgement: 126 uncached input tokens, 1,477 cache-read tokens for the system prompt, and 14 (Haiku) or 17 (Sonnet) output tokens. The gap in cost is the price list. claude-haiku-5-5 costs $0.10 per million input tokens, $0.50 per million output tokens and $0.01 per million cache reads. claude-sonnet-5-5 costs $2, $10 and $0.10. Input and output are 20 times dearer on Sonnet, but cache reads only 10 times. Cache reads are most of each judgement's tokens, so the blend comes out near 16. On this criterion and this set, the cheaper judge was at least as good and about 16 times cheaper per judgement.
Don't generalize that choice. The planted defects are blatant: a credit the reply simply grants, a number off by hours. Every judge caught all 30, so TPR is 1.00, with a 95% interval of 0.886 to 1.0. Thirty blatant failures can't show more than that. Whether these judges catch subtler defects, such as a correct outcome in hedged wording, this set doesn't test. Add such cases when your review queue finds them.
9. Common problems
- A verdict comes back as
None. The response was a refusal or was cut off, andcalibration.pycounts it as FAIL.no_verdictinruns/calibration.jsoncounts them; it was 0 in every recorded run. NotRecordedafter editing a reference reply. The judge's input changed, so its key no longer matches a recorded call. Re-runscripts/build_labels.py, then record withuv run --env-file .env python calibrate.py --live --record, which needsANTHROPIC_API_KEYin.env.- Your live numbers differ from the recorded ones. Judges vary between runs. Calibrate before you trust a judge, and again whenever you change its model or criterion.
10. Exercise
Simulate a judge with a bias against apologies. FakeModel(respond) calls respond(system, user) and returns its dict, and the user turn holds the reply between <reply> tags. Write a respond that agrees with every label, except that it answers FAIL for any reply containing "sorry". tests/test_calibration.py has _oracle(labels) to start from. Then call run_judge(model, labels, by_id, kb, "v2") and report(rows), and assert on TPR, TNR and kappa.
Verify. The report shows TPR 1.00 and TNR 0.933, with 28 of 30 good replies passed, because two good replies (L41 and L55) apologize. Its kappa is 0.933. Your test brings uv run pytest tests to 34 passed.
11. The checklist so far
| Gap | Status |
|---|---|
| No written expectation per ticket | Closed in Lesson 2 |
| No mechanical checks | Closed in Lesson 2 |
| Prose: answers the question, promises nothing unsupported | Closed for this criterion: a judge measured against 60 labels (Haiku 5.5, criterion v2, TPR 1.00, TNR 1.00), with the limits above |
| "v2 looks better" is an opinion | Lesson 4 |
| Nothing stops a regression; nobody looks at real traffic | Lesson 5 |
12. What comes next
Lesson 4 writes prompt v2 for the drafter and asks whether it is better than v1. It uses the code graders, both judges and a pairwise comparison, and finds that 40 cases can't tell a small improvement from noise.

