LLM as a judge
A language model can grade other models' answers quickly and cheaply, if you give it a clear rubric, check it for known biases and compare it with human judgement.
In 60 seconds
LLM as a judge
A language model can grade other models' answers quickly and cheaply, if you give it a clear rubric, check it for known biases and compare it with human judgement.
Two common set-ups
| Set-up | How it works | Good for |
|---|---|---|
| Single-answer grading | The judge reads one answer and gives a score or pass/fail against a rubric. | Tracking quality over time; checking must-have points |
| Pairwise comparison | The judge sees two answers to the same input and picks the better one, or a tie. | Comparing two models or two prompts |
Write a rubric, not a vibe
You are grading an answer to a farmer's question about crop insurance.
Use ONLY the reference facts below. Answer each check with YES or NO,
then give a one-line reason for each.
1. CORRECT: Every deadline, amount and document mentioned matches the reference facts.
2. COMPLETE: The answer includes the must-include points listed.
3. NO_INVENTION: The answer does not state any scheme, number or rule
that is missing from the reference facts.
4. LANGUAGE: The answer is in the same language as the question.
5. CLEAR: A farmer with basic reading skills could follow it.
Return JSON: {"CORRECT": "YES|NO", "COMPLETE": ..., "NO_INVENTION": ...,
"LANGUAGE": ..., "CLEAR": ..., "reasons": [...]}Known biases
| Bias | What happens | What to do |
|---|---|---|
| Position bias | In pairwise tests, the judge tends to favour the answer shown first (or second). | Run each pair twice with the order swapped. Count a win only if the judge agrees in both orders; otherwise call it a tie. |
| Length bias | Longer, more detailed-looking answers get higher marks even when they are not better. | Tell the judge not to reward length; include short correct answers in calibration; check whether scores rise with length. |
| Self-preference | A judge may rate answers from its own model family more highly. | Where possible, use a judge from a different family than the models being compared, and check against humans. |
| Style over substance | Confident tone and nice formatting can hide wrong facts. | Give the judge reference facts and make correctness its own yes/no check. |
def call_model(prompt: str) -> str:
... # plug in your provider; return the judge's text reply
JUDGE = """Question: {q}
Answer A: {a}
Answer B: {b}
Which answer is more correct and helpful? Ignore length and style.
Reply with exactly one of: A, B, TIE"""
def judge_once(q, first, second):
reply = call_model(JUDGE.format(q=q, a=first, b=second)).strip().upper()
return reply if reply in {"A", "B", "TIE"} else "TIE"
def compare(q, ans_x, ans_y):
r1 = judge_once(q, ans_x, ans_y) # x shown as A
r2 = judge_once(q, ans_y, ans_x) # x shown as B
if r1 == "A" and r2 == "B":
return "X"
if r1 == "B" and r2 == "A":
return "Y"
return "TIE" # judge changed its mind: no clear winnerCalibrate against humans
- 1
Label a sample by hand
Have people grade a sample of outputs with the same rubric. - 2
Run the judge on the same sample
Use the exact prompt and settings you will use later. - 3
Compare
Measure agreement (for example, Cohen's kappa from Lesson 6) and read the disagreements. - 4
Fix the rubric
Most disagreements come from unclear wording. Tighten it and repeat. - 5
Re-check regularly
Re-calibrate when you change the judge model, the rubric or the task.
Watch and read more
Lab
A judge rubric, calibrated against your own grades on 10 answers.
The problem
- Take 10 items from your test set (Lesson 4). For each, collect one answer from any chatbot you are allowed to use.
- Write a rubric with 3–5 yes/no checks, like the example in this lesson.
- Grade all 10 answers yourself with the rubric. Hide your grades.
- Give the rubric, the reference facts and each answer to an LLM (by hand in a chat window, or with the starter script and your own provider function).
- Count how often you and the judge agreed on each check. Read every disagreement and rewrite the unclear parts of the rubric.
Practice lab
Edit the code and run it. Python runs in your browser — nothing is sent to our server.
No output. Add print(...) to see values.
You are done when
Hard questions
Try to answer before you reveal. If you can answer these, you understood the lesson.
Q1Your judge agrees with you 95% of the time on CORRECT, but your test set is 95% correct answers. Is the judge good?Reveal
You cannot tell yet. A judge that always says YES would also agree 95% of the time. Raw agreement is misleading when one label is very common. Look at how the judge does on the few wrong answers, and use a chance-corrected measure such as Cohen's kappa (Lesson 6).
Q2When is an LLM judge a poor choice even after calibration?Reveal
When mistakes are very costly and the judge cannot check facts reliably, for example dosage advice or legal deadlines without clear references; when the content is in a language or domain where the judge itself is weak; and when the outputs being graded came from the same model family as the judge, so shared blind spots go unnoticed. In these cases use expert human review, perhaps with the judge only as a first filter.
Questions people ask
Why not just use a bigger model as the judge and trust it?
A stronger judge often helps, but the known biases do not disappear on their own, and the judge does not know your domain rules unless you give them. You only know how much to trust it after comparing it with human labels on your own data.
Should the judge see a reference answer?
When you have one, usually yes. Grading against reference facts is more reliable than asking the judge to decide what is true from its own knowledge. Without references, the judge can reward confident mistakes.
Should the judge explain its reasoning?
Asking for a short reason for each check helps you debug disagreements and makes the grade easier to audit. Ask for the reasons in a fixed format, and read a sample of them.
Will the judge give the same grade every time?
Not always. Model outputs can vary between runs. Use settings that reduce randomness where your provider supports them, run important comparisons more than once, and look at the rate of changes between runs.
Lesson test
5 questions. Get 3 right (60%) to pass and complete this lesson.