Sub topic 10
Calibrate an LLM judge against human labels
This chapter assumes you can read and write basic Python, handle JSONL files, and know what a prompt and a model output are. You should also know the mean and a proportion from elementary statistics. You should have a labeled dataset from earlier chapters, with references or rubrics and a measure of annotator agreement.
Why a judge needs calibration
An LLM judge is a model call that reads an app output, often with a reference or rubric, and returns a grade such as pass or fail. Judges are attractive because they grade open-ended text at a low cost. They are also a measuring instrument, and an instrument you have not checked gives numbers you cannot trust.
Known judge failure modes include:
- Leniency or harshness. The judge passes too many or too few outputs compared with people.
- Length bias. Longer answers get higher grades even when they are no better.
- Position bias. In pairwise comparisons, the answer shown first wins more often.
- Self-preference. A judge tends to favor outputs written by the same model family.
- Rubric drift. The judge applies the rubric differently on different slices, such as strict on policy questions and loose on small talk.
Calibration means comparing the judge's grades with human grades on the same cases, measuring the gap, and changing the judge until the gap is acceptable. Once you have done that, you can report judge-based scores with a known level of trust.
The calibration workflow
The workflow has five steps. You repeat steps 3 to 5 until the judge is good enough.
- Build a human-labeled calibration set.
- Run the judge on the same cases.
- Compare the two sets of grades with agreement metrics and a confusion matrix.
- Read the disagreements and find the pattern.
- Revise the judge prompt, then re-run on a held-out part of the calibration set.
Build the calibration set
Use cases that people have already labeled. Two properties matter more than size.
- Representative labels. Include easy, hard, and borderline cases, and include both passes and failures. If 95% of your cases pass, a judge that always says pass looks 95% accurate. Oversample failures so each class has at least 30 to 50 examples if you can.
- Reliable labels. Humans must agree with each other first. If two annotators reach a kappa of only 0.4, no judge can reach a much higher agreement with them. Fix the rubric before you tune the judge.
Keep the calibration set separate from the examples you place in the judge prompt. If a case appears in the prompt as a few-shot example and also in the calibration set, your agreement number is inflated. Split the calibration set in two. Use one half, the tuning half, to read disagreements and revise the prompt. Use the other half, the check half, only to report the final agreement. This is the same leakage idea you applied to dev and test splits, applied to the judge itself.
Measure agreement
Raw agreement is the share of cases where the judge and the human give the same grade. It is easy to read, but it hides chance agreement. Cohen's kappa corrects for it, and the function below is the one from the earlier chapter on annotator agreement.
def cohens_kappa(a, b):
n = len(a)
observed = sum(x == y for x, y in zip(a, b)) / n
labels = set(a) | set(b)
expected = sum((a.count(l) / n) * (b.count(l) / n) for l in labels)
if expected == 1:
return 1.0
return (observed - expected) / (1 - expected)Here is a worked example with 10 cases. A value of 1 means pass and 0 means fail.
human = [1, 1, 1, 1, 1, 1, 0, 0, 0, 0]
judge = [1, 1, 1, 1, 1, 1, 1, 1, 0, 0]
observed = sum(h == j for h, j in zip(human, judge)) / len(human)
print("raw agreement:", observed)
print("kappa:", round(cohens_kappa(human, judge), 3))Raw agreement is 0.8. The human labels have six passes and four fails. The judge has eight passes and two fails. The expected chance agreement is 0.6 × 0.8 + 0.4 × 0.2 = 0.56. Kappa is (0.8 − 0.56) / (1 − 0.56) ≈ 0.545. That is moderate agreement, and it is much lower than the 0.8 suggests.
The numbers also show the direction of the error: the judge is lenient. It passed two cases that humans failed and never failed a case that humans passed.
Look at both error types
Kappa is one number. A confusion matrix tells you which way the judge errs, and that matters because the two errors have different costs.
from collections import Counter
def confusion(human, judge):
counts = Counter(zip(human, judge))
return {
"true_pass": counts[(1, 1)],
"true_fail": counts[(0, 0)],
"false_pass": counts[(0, 1)],
"false_fail": counts[(1, 0)],
}
def precision_recall_for_failures(human, judge):
c = confusion(human, judge)
caught = c["true_fail"]
flagged = c["true_fail"] + c["false_fail"]
actual = c["true_fail"] + c["false_pass"]
precision = caught / flagged if flagged else 0.0
recall = caught / actual if actual else 0.0
return precision, recall
print(confusion(human, judge))
print(precision_recall_for_failures(human, judge))On the example data, the judge catches two of the four real failures, so recall for failures is 0.5, and every failure it flags is real, so precision is 1.0. Treat the failure class as the one you care about. A judge that misses half of the failures will make your app look better than it is.
| Judge error | Meaning | Effect on your results |
|---|---|---|
| False pass | Judge passes an output humans failed | Scores are too high, regressions go unnoticed |
| False fail | Judge fails an output humans passed | Scores are too low, you chase problems that do not exist |
Choose a threshold
There is no universal cutoff. A common reading of kappa is: below 0.4 is weak, 0.4 to 0.6 is moderate, 0.6 to 0.8 is substantial, and above 0.8 is strong. Pick a target based on what the judge decides.
- To rank two prompt versions on average, moderate agreement can be enough if the errors are not biased toward one version.
- To gate a release or flag individual outputs, aim for substantial agreement and high recall on failures.
- Your target should not exceed the agreement between your human annotators. Human agreement is the ceiling.
Quantify the uncertainty
With a calibration set of 60 cases, agreement is itself an estimate. Use the bootstrap function from the dataset-size chapter on per-case match scores, where each score is 1 if the judge matched the human and 0 if not.
import random
def bootstrap_ci(scores, n_boot=1000, alpha=0.05, seed=0):
rng = random.Random(seed)
n = len(scores)
means = sorted(sum(rng.choices(scores, k=n)) / n for _ in range(n_boot))
lo = means[int(n_boot * alpha / 2)]
hi = means[int(n_boot * (1 - alpha / 2)) - 1]
return lo, hi
matches = [int(h == j) for h, j in zip(human, judge)]
print(bootstrap_ci(matches))On 10 cases the interval will be very wide. That is the point: it shows that 10 cases cannot support a claim such as "the judge agrees 80% of the time." Report the interval beside the number.
Revise the judge
Read the disagreements on the tuning half before changing anything. Group them by cause, then apply the matching fix.
- Vague criteria. Rewrite the rubric as specific, checkable statements. "Answer is correct" becomes "The answer states the 30-day return window and does not promise a refund after it."
- Judge too lenient. Add explicit failure conditions and one or two examples of near-misses that must fail.
- Length bias. Tell the judge to ignore length and style, and check whether the failures concentrate on long outputs.
- Output format errors. Ask for a short reason first and a fixed label last, such as
PASSorFAIL, and parse only that label. Treat an unparsable reply as an error, not as a fail. - Noisy grades. Set the temperature to 0, and run the judge more than once on a sample to measure how often it changes its own grade.
Change one thing at a time, so you know what helped. After each change, re-run the judge on the tuning half. Use the check half only once you think you are done. If you read the check half's disagreements and edit the prompt in response, it becomes another tuning half and you need fresh cases.
Check slices, not just the total
A judge can agree well overall and poorly on one slice. Compute agreement per tag, the same way you report app scores per tag.
from collections import defaultdict
def agreement_by_tag(cases, human, judge):
by_tag = defaultdict(list)
for c, h, j in zip(cases, human, judge):
for tag in c["tags"]:
by_tag[tag].append(h == j)
return {tag: sum(v) / len(v) for tag, v in by_tag.items()}If the judge agrees on 95% of returns cases but 60% of adversarial cases, a headline agreement number hides the problem. Slices with few cases give noisy estimates, so note the count next to each value.
Keep the judge calibrated over time
A calibrated judge stays calibrated only while its inputs stay the same. Treat the judge as a versioned part of the evaluation.
- Record the judge model name, the prompt text or its hash, and the calibration date with every eval run.
- Re-calibrate when you change the judge model, edit the rubric, or when the app's outputs change style.
- Re-check a small sample, say 20 cases, of human labels against judge grades on a regular schedule, and add new production failures to the calibration set.
- Do not compare scores from different judge versions as if they were the same measurement.
If the judge cannot reach your target after several rounds, use a different grader. Code-based checks work for outputs with structure, and human review works for a small, high-stakes sample.
Summary of the checks
| Check | What it tells you | Warning sign |
|---|---|---|
| Raw agreement | Share of identical grades | High value with a skewed class mix |
| Cohen's kappa | Agreement beyond chance | Below the human-to-human kappa by a wide margin |
| Confusion matrix | Direction of errors | Many false passes |
| Failure recall | Share of real failures caught | Below your release target |
| Bootstrap interval | Uncertainty at this sample size | Interval wider than the margin you care about |
| Per-slice agreement | Where the judge is weak | One slice far below the others |
| Repeat run stability | Noise in the judge itself | Grades change between identical runs |
Exercise
A judge and a human grade 20 cases. The human gives 16 passes and 4 fails. The judge gives 18 passes and 2 fails, and it agrees with the human on 16 cases in total. Compute raw agreement and Cohen's kappa. Then say whether the judge is safe to use for flagging failing outputs.
Show answer
Raw agreement is 16/20 = 0.8. Expected chance agreement is 0.8 × 0.9 + 0.2 × 0.1 = 0.72 + 0.02 = 0.74. Kappa is (0.8 − 0.74) / (1 − 0.74) = 0.06 / 0.26 ≈ 0.23, which is weak. The judge is not safe for flagging failures. The human labeled 4 fails and the judge labeled only 2, so it misses at least 2 real failures. Raw agreement looks good only because most cases pass.
Exercise
Your judge reaches kappa 0.75 on the cases you used while rewriting its prompt. A colleague wants to report this number in the eval results. What is wrong, and what should you do?
Show answer
The cases were used to tune the prompt, so the judge has been fit to them and the number is optimistic. Hold out a check half of the calibration set that you never read while editing, and report kappa on that half with a bootstrap interval. If you have already read it, collect and human-label fresh cases.