Many qualities that matter, such as whether an answer is faithful to the sources, complete, polite, or actually helpful, cannot be checked with string matching. The common solution is an LLM-as-judge: a model that grades outputs against a rubric. Judges scale where humans cannot, but an uncalibrated judge is just a confident random number generator. This lesson covers when to use a judge, pointwise versus pairwise judging, writing rubrics that produce consistent verdicts, the known biases of judges, and the calibration process that tells you whether to trust one.
- Decide when a judge is appropriate and when code or humans are better
- Choose between pointwise, pairwise and reference-based judging
- Write rubrics that produce consistent, explainable verdicts
- Detect and mitigate position, verbosity and self-preference biases
- Calibrate a judge against human labels and monitor it over time
When to use a judge
Use code first: if a check can be written as a rule (valid JSON, contains the order ID, called the refund tool), a rule is cheaper, faster and perfectly consistent. Use humans for ground truth and for high-stakes decisions. Use a judge for the large middle: qualities that need reading comprehension, applied to more outputs than humans can review.
| Style | How it works | Best for |
|---|---|---|
| Pointwise | Grade one output against a rubric (pass/fail or a small scale) | Tracking a metric over time |
| Pairwise | Show outputs A and B, ask which is better | Comparing two versions; more sensitive |
| Reference-based | Compare the output to a known good answer | Factual questions with a target |
| Reference-free | Judge against the rubric and sources only | Open-ended tasks without one right answer |
Rubrics that produce consistent verdicts
Vague rubrics ("rate helpfulness from 1 to 10") produce vague, unstable scores. Good rubrics break quality into specific, mostly binary criteria, define each with an example, and ask the judge to reason before deciding. Binary or three-level scales are far more consistent than ten-point scales.
You are grading an answer from a customer-support assistant.
SOURCES:
{sources}
QUESTION:
{question}
ANSWER:
{answer}
Check each criterion:
1. Every factual claim in the ANSWER is supported by the SOURCES.
2. The ANSWER does not contradict the SOURCES.
3. If the SOURCES do not contain the answer, the ANSWER says so instead of guessing.
First write one sentence of reasoning per criterion.
Then output exactly one line: VERDICT: PASS or VERDICT: FAIL
(PASS only if all three criteria hold.)import re
def judge_faithfulness(sources: str, question: str, answer: str) -> tuple[bool, str]:
prompt = JUDGE_TEMPLATE.format(sources=sources, question=question, answer=answer)
out = call_llm(prompt, temperature=0)
m = re.search(r"VERDICT:\s*(PASS|FAIL)", out)
if not m:
return False, "unparseable verdict: " + out[-200:] # count as failure, investigate
return m.group(1) == "PASS", outKnown judge biases
- Position bias: in pairwise judging, preferring whichever answer is shown first (or second). Mitigation: judge both orders and count a win only if it holds in both.
- Verbosity bias: preferring longer, more detailed answers even when they are worse. Mitigation: rubric criteria about concision and relevance; compare at similar lengths.
- Self-preference: favouring outputs from the same model family as the judge. Mitigation: use a different family as judge where possible, and check against human labels.
- Leniency: passing almost everything. Mitigation: binary criteria, explicit fail examples, calibration.
- Format sensitivity: verdicts change with markdown, ordering or whitespace. Mitigation: normalise outputs before judging.
Pairwise judging in both orders
Pairwise judging asks a simpler question than pointwise grading (which of these two is better?), so it detects smaller differences between versions. The price is position bias. Run every comparison twice with the answers swapped, and count a win only when both orders agree; a disagreement is recorded as a tie. The share of flipped verdicts is itself a useful health metric for the judge: if it is high, the rubric is too vague for the judge to apply.
def pairwise(question: str, a: str, b: str) -> str:
first = call_llm(PAIR_TEMPLATE.format(q=question, x=a, y=b), temperature=0)
second = call_llm(PAIR_TEMPLATE.format(q=question, x=b, y=a), temperature=0)
win1 = "A" if "WINNER: X" in first else "B"
win2 = "B" if "WINNER: X" in second else "A"
return win1 if win1 == win2 else "tie" # order-dependent verdicts count as tiesCalibrating a judge
A judge is an instrument, and instruments need calibration. Have humans label a sample of outputs (100 is a good start, covering passes, fails and borderline cases), run the judge on the same outputs, and compare. Look at overall agreement and, more importantly, at where they disagree: false passes are usually more dangerous than false fails.
def agreement(human: list[bool], judge: list[bool]) -> dict:
n = len(human)
agree = sum(h == j for h, j in zip(human, judge)) / n
ph, pj = sum(human) / n, sum(judge) / n
expected = ph * pj + (1 - ph) * (1 - pj) # agreement by chance
kappa = (agree - expected) / (1 - expected) if expected < 1 else 1.0
false_pass = sum((not h) and j for h, j in zip(human, judge))
return {"agreement": agree, "kappa": kappa, "false_passes": false_pass}Cohen's kappa corrects raw agreement for chance: with a 90% pass rate, two raters who both say PASS to everything agree 90% of the time but have a kappa of 0. As a rough guide, kappa above about 0.6 is substantial agreement and above 0.8 is strong. Iterate on the rubric until agreement is good, then freeze the judge prompt and model version. Re-run the calibration whenever you change either, because a judge upgrade silently changes every score you report.
Using judges responsibly
Keep a human in the loop on a small, regular sample even after calibration, and route disagreements and low-confidence verdicts to review. Report judge-based scores with the judge version and its measured agreement, so readers know how much to trust them. Remember cost: a judge call per output can double the cost of an eval, so reserve judges for criteria code cannot check, and cache verdicts for unchanged outputs.