Sub topic 3
Calibrate an LLM Judge Against Human Labels
Assume you know basic Python, JSONL, LLM app calls, prompts, and proportions. This chapter covers the final steps that make evaluation results trustworthy.
Calibrate the judge
An LLM judge scores an app response against a rubric. Before trusting it, compare its decisions with human labels on a calibration set that humans reviewed independently.
Use a fixed prompt, rubric, model, and score scale. Measure agreement with accuracy or Cohen’s kappa. Kappa adjusts for agreement that could happen by chance.
def cohens_kappa(human, judge):
n = len(human)
observed = sum(a == b for a, b in zip(human, judge)) / n
labels = set(human) | set(judge)
expected = sum(
(human.count(label) / n) * (judge.count(label) / n)
for label in labels
)
return 1.0 if expected == 1 else (observed - expected) / (1 - expected)Inspect disagreements. Revise the rubric when humans disagree for a clear reason. Do not silently change human labels to match the judge.
Split data and avoid leakage
Keep development cases separate from test cases. Use the development set to improve prompts and rubrics. Use the test set only for final comparisons.
Hashing an immutable case ID makes the assignment repeatable:
import hashlib
def split_for(case_id, test_percent=20):
value = int(hashlib.sha256(case_id.encode()).hexdigest(), 16)
return "test" if value % 100 < test_percent else "dev"Avoid leakage: do not place near-duplicates, future reference answers, or test-derived examples in development prompts.
Estimate dataset size
More cases reduce uncertainty, but slices need enough cases to reveal failures. Report a proportion with a confidence interval, not only a percentage. Bootstrap per-case scores when an exact statistical model is inconvenient. Treat small slices as signals for investigation, not precise rankings.
Version and store the dataset
Store each JSONL case with an immutable ID, input, reference or rubric, tags, provenance, and difficulty. Version dataset changes separately from application code. Record the dataset version, model, prompt, judge, and timestamp with every evaluation.
Run and read the eval
Run the same cases with the same settings, then report overall and per-slice scores. A high overall score can hide poor performance on adversarial or high-risk slices.
Keep the dataset alive
Turn production failures into new cases. Remove secrets and personal data, preserve the failure pattern, label the expected behavior, and tag its source. Review recurring failures for missing slices or unclear rubrics. Re-run old cases after every meaningful prompt, model, or tool change.
Exercise
Why should near-duplicate test cases not appear in both development and test sets?
Show answer
They leak information between the sets, so the test score may measure memorization instead of generalization.