A judge model can agree with humans over 80% of the time, as often as two humans agree with each other. The same judge favors the first answer and the longer answer. Edit its prompt and watch both pulls move.
Learn how to grade agent runs that have no single right answer, and how to check that the grader tells the truth.
Switch the four prompt fixes on and off. Watch the agreement with humans and the two bias meters. Then we build, piece by piece, the grader types, the judge prompt, the biases and the checks that make a verdict worth trusting.
You need the idea of a benchmark (a fixed task set with a score) and a little Python. We build the rest from zero.
Based on Lecture 15 of Stanford CS 329Z: Engineering AI Agents (Fall 2026), taught by Diyi Yang, Michael Ryan and John Yang, and its readings: Anthropic, Demystifying Evals for AI Agents; Zheng et al., Judging LLM-as-a-Judge with MT-Bench and Chatbot Arena; Ryan et al., AutoMetrics; and AutoLibra. Lecture slides: PDF, on the course site. Every idea is re-taught here in our own words and devices; it follows Lecture 13, Evaluation Fundamentals.
The over 80% agreement is from Zheng et al. (slides 47 and 48). The judge is a toy made for this page. Each of 40 pairs has a true quality gap. The judge adds noise, a bonus for the first slot and a bonus for the longer answer. Each fix shrinks one term. Illustrative, not a real model.
Chapter 0
See what code checks miss, and how a wrong grader raises or lowers a benchmark score
You ask an agent to make a function easier to read. It returns working code. A unit test passes on the old code and on the new code. The test cannot see readability.
A grader is the part of a benchmark that turns a run into a score. Code graders come first: answer == gold grades a fact, pytest grades a bug fix, and a database check grades an order. They are cheap and exact. But they miss four things:
A grader can also be wrong. Every verdict lands in one of four cells.
| In reality \ grader says | Correct | Incorrect |
|---|---|---|
| Correct | True positive | False negative. On tau2-bench, Claude Opus 4.5 found a better solution than the grader expected. |
| Incorrect | False positive. In SWE-bench, some patches pass the target tests but fail tests nobody registered. | True negative |
Use the device. Ten runs are graded by a strict answer key. Fix the key, then fix the tests.
Top row: what is true. Bottom row: what the grader says. Teal is correct, grey is wrong. A red ring marks a grader mistake.
Illustrative toy: 6 of 10 runs are truly correct. The two kinds of mistake come from the lecture (slide 8): a valid alternative the key rejects, and a patch that passes only the registered tests. FN is a false negative. FP is a false positive.
Worked number. True score: 6 of 10. The flawed grader says 6 − 2 + 1 = 5. It rejects 2 good runs and passes 1 bad run, so the score is off by 1 and the ranking can flip.
Symptom: a strong model scores below a weak one on tasks you can read yourself. Measurement: read 20 failed runs and count how many were valid. Fix: widen the key, add the missing tests, and check the final state, not the agent’s claim.
Chapter 1
Compare code, human and judge graders, then combine them so each covers the others’ gaps
Your team ships an agent every week. A human panel takes two weeks to grade it. A unit test takes two seconds but misses the writing quality. You need to pick a grader for each part of the task.
| Grader | Cost | Speed | Reliable | Flexible | Scales | Nuance |
|---|---|---|---|---|---|---|
| Code | Cheap | Fast | Yes | Low | High | Low |
| Human | Expensive | Slow | Partly | High | Low | High |
| LM judge | Moderate | Fast | Partly | High | High | High |
Each grader can look at two things: the final environment state (the repo, the database) or the trajectory (the steps the agent took).
Code graders run scripts: string match, unit tests, state checks, static analysis, tool-call checks.
They have three limits. They are prescriptive: the solution must use the checked function. They are static: tests never evolve. They are reductive: what the tests skip counts as a pass.
Human graders vote on the work. Three setups from the lecture:
| Setup | Who grades | How |
|---|---|---|
| Chatbot Arena | An anonymous crowd | Vote between two replies. Votes become Elo ratings. |
| GDPval | Experts from 44 occupations | Blind comparison with expert work. Score is win rate. |
| Co-Gym | Real users with their own tasks | Work with the agent, then rate outcome and process. |
Human votes are the gold standard, but they cost three things. They are expensive: every new model needs a new round, and a round takes days or weeks. Raters disagree, so report inter-annotator agreement. They are hard to rerun: the pool changes and the session cannot replay.
The lecture’s advice is to combine. Use code where you can, an LM judge where you must, and humans with care. Anthropic’s guide says the same: model graders need calibration against human graders, and occasional human review is enough once the system is robust. Three ways to merge the scores:
The unit tests pass. Slide the judge’s rubric score and compare the two rules. A green band means pass.
The two rules are the lecture’s (slide 23, plus calibration against human spot checks, which Chapter 8 covers). The weights, the threshold of 7 and the cut of 0.8 are illustrative.
Worked number. Tests pass (1.0), rubric 6. All-must-pass fails, because 6 is under 7. Weighted gives 0.6 × 1.0 + 0.4 × 0.6 = 0.84, which passes. Same run, two verdicts. State the rule beside the score.
Failure: a score that moved when nobody changed the agent. Measure: rerun the merge on stored scores with the other rule. Fix: pick the rule before you see results.
Chapter 2
Build a judge from a prompt, ask it in four ways, and see what it inherits from code and from humans
A judge is a language model that you prompt with a rubric. The prompt holds the task, the answer and the rules. The reply is a verdict. It scales like code and judges like a human, and it inherits problems from both.
There are four ways to ask. Pick one in the device. The example is the lecture’s: explain why the sky is blue to a 10 year old.
The four checks are the lecture’s (slide 20) and the two sample answers are its sky example (slide 52). The prompt wording and the verdicts are illustrative.
Benchmarks differ in how much judgment they hand to the judge.
| Benchmark | The judge sees | It decides |
|---|---|---|
| BrowseComp, HLE | Response and gold answer | Is the final answer equivalent? |
| MT-Bench | A multi-turn chat | A score from 1 to 10, or the better of two |
| AlpacaEval | The model’s reply and a reference reply | Which is better (length-controlled win rate) |
The judge inherits three problems, and the next chapters fix them one by one. It is non-deterministic: the same input can get different verdicts, so sample several times or use several judges. It is biased: it favors certain positions, longer answers and its own style. It needs calibration: it is only as good as its agreement with humans.
Anthropic’s guide adds two habits. Give the judge a way out, such as returning “Unknown”. Grade each dimension with its own judge instead of one judge for all.
pythondef judge(task, answer, rubric, call_llm): # call_llm: str -> str prompt = (f"Task: {task}\nAnswer: {answer}\nRubric: {rubric}\n" "Think step by step, then end with 'Verdict: PASS', " "'Verdict: FAIL' or 'Verdict: UNKNOWN'.") reply = call_llm(prompt) # shape: free text last = reply.strip().splitlines()[-1] # the verdict is the last line return {"PASS": 1, "FAIL": 0}.get(last.split(":")[-1].strip(), None) # None = no verdict
Failure: scores shift when you reword the prompt. Measure: grade 50 fixed answers with two wordings and count verdict changes. Fix: fix the format, parse the last line only, and count None as its own bucket, not as a fail.
Chapter 3
Score a summary with a model instead of word overlap, and keep the judge’s uncertainty in the number
Your summary is correct but uses new words. ROUGE counts words shared with a reference, so it scores the summary low. Phase one of the lecture asks: can a language model replace such metrics?
The lecture tells the story in three phases: NLP metrics, then human preferences (Chapter 4), then human actions (Chapter 5). Three papers make up phase one.
| Paper | Method | Finding |
|---|---|---|
| G-Eval Liu et al., EMNLP 2023 | Give GPT-4 the criteria, such as coherence. It writes how it will judge, then gives a 1 to 5 score. | 0.514 Spearman with humans on summarization, well above earlier metrics. Early warning: it may favor LLM-written text. |
| GPTScore Fu et al., NAACL 2024 | Describe the aspect in an instruction. Score a text by how probable the model finds it. | 19 models (80M to 175B), 4 tasks, 22 aspects, 37 datasets. Describing task and aspect makes scores more reliable. |
| Chiang and Lee ACL 2023 | Give the model the same questionnaire that expert raters (English teachers) got. | Models rank texts like experts and stay stable across wording and sampling. They are more lenient on unnatural text. |
The G-Eval score keeps the judge’s doubt. It reads the probability the model gives to each score from 1 to 5, and averages.
Bars are the chance the judge puts on each score. Compare the one integer it would print with the weighted score.
The score rule is G-Eval’s (slide 28). The four probability sets are illustrative.
Worked number. Leaning high: p = 0.1 for a 3, 0.3 for a 4, 0.6 for a 5. Score = 3 × 0.1 + 4 × 0.3 + 5 × 0.6 = 0.3 + 1.2 + 3.0 = 4.5. The integer answer is 5. The weighted score also gives ties a break, and lets two summaries with the same integer differ.
pythondef expected_score(probs): # probs: {1: p1, ..., 5: p5} from the judge's token probabilities z = sum(probs.values()) # renormalise: the judge may spend mass on other tokens return sum(i * p for i, p in probs.items()) / z
Failure: the judge rates LLM-written text above human text of equal quality. Measure: take pairs that humans rated the same, one human-written and one LLM-written, and compare the mean judge scores. Fix: add human-written references, and check agreement per source.
Chapter 4
Learn a judge from human comparisons, test a prompted judge against them, and measure agreement the right way
Two chatbot replies sit side by side. A person picks one. Phase two asks three questions. Can we learn a judge from such picks? Can a prompted model stand in for the raters? Can we make that judge trustworthy? The same preference judge can score a model (evaluation) or reward it (training).
| Paper | What it did | Finding |
|---|---|---|
| Learning to summarize Stiennon et al., 2020 | Collect human comparisons of summaries. Train a reward model to predict the pick. Use it as the reward for RL. | Summaries beat human references and larger supervised models. The reward model predicts preferences better than ROUGE. |
| InstructGPT Ouyang et al., 2022 | The same three steps, beyond summaries. | Labelers preferred the 1.3B InstructGPT over the 175B GPT-3, a model 100 times larger. |
| MT-Bench and Arena Zheng et al., 2023 | Collect human preferences (80 multi-turn questions, Arena votes). Test three judge formats. | GPT-4 agrees with humans over 80% of the time, the same as humans agree with each other. It shows position, verbosity and self-enhancement bias. |
| Prometheus Kim et al., 2024 | Fine-tune Llama-2-Chat-13B on 1K rubrics, 20K instructions and 100K GPT-4 feedback. Input holds a rubric and a reference. | 0.897 Pearson with humans on 45 custom rubrics, close to GPT-4 (0.882) and far above GPT-3.5 (0.392). |
A judge can ask pointwise (“how good is this?”) or pairwise (“which is better?”). Either way, the number to report is agreement with humans. But raw agreement can fool you. Use the device.
100 answers. The judge starts as a rubber stamp that says “good” every time. Raise “Catches bad” and watch the two bars.
Cohen’s kappa goes with the agreement figures in the lecture (WebVoyager reports 85.3% with kappa 0.70, slide 59). The counts here are a toy made for this page.
Cohen’s kappa subtracts the agreement that two raters would reach by chance.
Worked number. 90 of 100 answers are good. The judge says “good” every time. po = 0.90. The judge says “good” always, so pe = 0.9 × 1 + 0.1 × 0 = 0.90. Kappa = (0.90 − 0.90) / 0.10 = 0. A 90% judge with no skill.
Failure: high agreement on a skewed set. Measure: report kappa and the per-class counts. Fix: test on a balanced set.
Chapter 5
Give the judge screenshots or a workspace to inspect, so it grades what the agent did and not what it said
An agent says, “Done. I ordered the black 64GB phone.” Is it true? Phase three asks whether a model can judge an agent’s actions and their effects, not only its words. A live website has no answer key or database to check.
| Paper | The judge sees | Finding |
|---|---|---|
| WebVoyager He et al., 2024 | Screenshots of the navigation and the final answer (GPT-4V) | Agent reaches 59.1% on live sites (40.1% text-only). The judge agrees with humans 85.3% of the time, kappa 0.70. Single sites differ by 10+ points. |
| Autonomous Evaluation Pan et al., 2024 | The instruction plus screenshots of the trajectory | 74.4 to 92.9% agreement with oracle metrics. As a reward, it improves a WebArena agent by 29% (relative) and an iOS agent by about 75%. |
| Agent-as-a-Judge Zhuge et al., 2025 | A judge agent that explores the workspace: locate, read, search, check the trajectory | On DevAI (55 tasks, 365 requirements): about 90% agreement with experts against about 70% for an LLM judge, at about 97% less time and cost than three experts. |
The pattern: the more of the run the judge can see, the better it agrees. Pick what the judge sees.
The task: buy the black 64GB phone. The agent picked a white 128GB phone and never paid. Lit boxes are what the judge can read.
The three levels of access follow WebVoyager, Pan et al. and Agent-as-a-Judge. The shopping run is an illustrative scene made for this page.
Is a judge good enough? The lecture’s answer is both yes and no. It is good enough to train with (+29% on WebArena). It is still off by 10+ points on some slices, such as single sites in WebVoyager. So check agreement per slice, not only overall.
Failure: the judge passes runs where the agent only claimed success. Measure: for the runs it passed, check the final state yourself. Fix: show the judge evidence, such as screenshots or tool access, and not the agent’s summary.
Chapter 6
Show the same two answers in both orders, count the flips, and cancel the bias by averaging
Two answers, A and B. You ask the judge, then swap them and ask again. If the judge changes its pick, the verdict depended on the order. Wang et al. found that changing the order alone let Vicuna-13B beat ChatGPT on 66 of 80 queries, with ChatGPT as the judge.
Model the judge’s lean as a bonus for the first slot.
Worked number. The good answer leads by 0.3, and b = 0.55. Good answer first: s = 0.3 + 0.55 = 0.85, so the judge picks it. Swap the order: s = −0.3 + 0.55 = 0.25, still above 0, so the judge picks the bad answer. The verdict flipped. Average the two runs, scored for the good answer: (0.85 + (−0.25)) / 2 = 0.30. The bonus cancels and the good answer wins.
Each dot is one pair, green if the verdict is right. A purple ring means the verdict flipped when the order flipped. Raise the bonus, then switch on both orders.
Illustrative toy judge, the same 40 pairs as the hero. The fix is Balanced Position Calibration from Wang et al., which averages both orders. Counts change a little with the bonus because the noise is fixed per pair.
pythondef judge_both_orders(task, a, b, ask): # ask(task, first, second) -> score for the first answer s1 = ask(task, a, b) # a shown first s2 = ask(task, b, a) # b shown first margin = (s1 - s2) / 2 # the position bonus appears in both and cancels return "a" if margin > 0 else "b" if margin < 0 else "tie"
Failure: a ranking that changes when you shuffle the pairs. Measure: flip rate, the share of pairs whose pick changes with the order. Fix: judge both orders, average, and send high-flip pairs to a human. Wang et al. also propose that last step.
Chapter 7
Pad a weaker answer and watch it win, then remove the length term the way Length-Controlled AlpacaEval does
A judge reads two answers. One is shorter and better. The other is padded. Judges favor longer answers, and models learned to exploit that. Dubois et al. ask: what would the preference be if both answers had the same length?
Their method fits a regression that predicts the judge’s preference from the model, the instruction and the length difference. Then it sets the length difference to zero. In our toy, the win chance of answer B is:
Answer B is worse. Add words to it and watch its win chance. Then switch on length control.
Illustrative numbers made for this page: g = −0.8 and w = 0.9 per 100 words. The real method fits these terms to a judge’s preferences.
Worked number. B adds 200 words, so Δlen = 2. logit = −0.8 + 0.9 × 2 = 1.0, and B wins with chance 1 / (1 + e−1) = 73%. With length control, logit = −0.8, and B wins 31% of the time. The weaker answer goes back to losing.
The result: the length-controlled score is much harder to game with verbosity. Its Spearman correlation with Chatbot Arena rises from 0.94 to 0.98.
Failure: a model gains on the leaderboard after a style change, not a skill change. Measure: compare the win rate when you ask for concise answers and verbose answers. Fix: control for length, or tell the judge to ignore it and test that it does.
Chapter 8
Build a judge from a small set of human labels, and know how far to trust the agreement you measure
You wrote a judge prompt for your product. You have 50 answers that users rated. Does the judge match them? Real user feedback is the gold standard, but it is scarce for a new task. So the question is how few labels you need.
AutoMetrics (Ryan et al., ICLR 2026) answers with a recipe:
Across 5 tasks, it raised Kendall correlation with human ratings by up to 33.4% over a plain LLM judge, with fewer than 100 labels. Kendall correlation compares two rankings: it counts item pairs ranked the same way minus pairs ranked oppositely. The fitted score also worked as a proxy reward, close to a verifiable one.
Order and length bias lean the same way every time, so more examples do not cancel them. Only a check against humans exposes them. But a small label set gives a noisy agreement number.
The band is where the judge’s true agreement probably lies. The dashed line is 80%, the human to human rate in the MT-Bench study.
The 80% line is from Zheng et al. The band uses the normal approximation, which is rough at small n or near 100%. The labels and agreement are illustrative.
Worked number. Agreement 85%, n = 50: √(0.85 × 0.15 / 50) = 0.05, so the margin is ±9.9 points, a band of 75 to 95. It includes 80%. With n = 300 the margin is ±4.0 and the band is 81 to 89. Now you can say the judge matches the human rate.
pythonfrom math import sqrt def validate_judge(verdicts, labels, swapped): # 0/1 lists, one entry per pair; swapped = verdicts with the order flipped n = len(labels) p = sum(v == y for v, y in zip(verdicts, labels)) / n # raw agreement pj, ph = sum(verdicts) / n, sum(labels) / n # how often each says "good" pe = ph * pj + (1 - ph) * (1 - pj) # chance agreement kappa = (p - pe) / (1 - pe) if pe < 1 else 1.0 flips = sum(a != b for a, b in zip(verdicts, swapped)) / n # same pairs, order swapped margin = 1.96 * sqrt(p * (1 - p) / n) return {"agreement": p, "kappa": kappa, "flip_rate": flips, "pm": margin}
Failure: the judge looks fine overall but is wrong on one slice. WebVoyager’s judge matched humans overall, but single sites differed by 10+ points. Measure: agreement per slice, with its own margin. Fix: add labels for the weak slice and refine the prompt. Anthropic’s guide gives the habit: read transcripts and grades from many trials, because failures should look fair.
Chapter 9
Report a run of tries in a way that says whether you can retry, or must count on every try
You run one task five times and get fail, pass, fail, fail, pass. How do you report it?
| Report | Says | Hides |
|---|---|---|
| Average (40%) | The expected success per try. | Is each try a coin flip, or is the task all pass or all fail? |
| At least once (yes) | The agent can solve the task. | Luck, and the cost of retrying. |
| Every time (no) | You can count on it. | Near misses and infra failures. It falls toward 0 as k grows. |
pass@k (Chen et al., HumanEval) is the chance that at least one of k tries succeeds. pass^k (Yao et al., tau-bench) is the chance that all k tries succeed. Take all ways to pick k of the n trials. pass^k is the share that are all passes. With c passes in n trials:
Four tasks, four tries each. Agent A passes 2 of 4 tries on every task. Agent B passes every try on half the tasks and none on the rest.
The A and B agents and the 50%, 83%, 17% figures are the lecture’s example (slide 87). The try-by-try pattern in the grid is illustrative.
Worked number, agent A at k = 2: pass@2 = 1 − C(2,2)/C(4,2) = 1 − 1/6 = 83%. pass^2 = C(2,2)/C(4,2) = 1/6 = 17%. Agent B stays at 50% for both. At k = 4, A has pass@4 = 100% and pass^4 = 0%.
A per-try rate p compounds. Anthropic’s guide gives 75% per try over 3 tries: 0.753 = 42% for pass^3.
| Use | When | Example |
|---|---|---|
| pass@k | You can retry, and a check picks the winner. | Sample k patches and keep one that passes the tests. Search: any correct find is enough. |
| pass^k | Every try reaches a user or changes the world. | Customer service: each customer gets one try. Purchases and emails. |
Judges are nondeterministic too. Sample the judge several times, or use several judges, and report the spread. Failure: a number with no k. Measure: ask which of the two questions it answers. Fix: report k and the number of trials n beside every score. Without k, the number means nothing.
Chapter 10
Keep the terms, the numbers, the checklist and the code for building a judge you can trust
| Term | Meaning, and the number to remember |
|---|---|
| Grader | Turns a run into a score. Code is cheap and exact. Humans are the gold standard. A judge scales. |
| False negative, false positive | The grader rejects a good run. The grader passes a bad run. |
| Judge formats | Reference match, rubric score, pairwise pick, assertion. |
| G-Eval score | The sum of p(i) times i. 0.514 Spearman with humans on summaries. |
| MT-Bench result | GPT-4 agrees with humans over 80%, as often as humans agree with each other. |
| Prometheus | 0.897 Pearson, against 0.882 for GPT-4 and 0.392 for GPT-3.5. |
| Agent-as-a-Judge | About 90% agreement with experts against about 70% for an LLM judge. |
| Position bias | The verdict depends on the order. Fix: judge both orders. Flip rate measures it. |
| Length bias | Longer answers win. Fix: length control. Spearman with Arena 0.94 to 0.98. |
| Cohen’s kappa | Agreement minus chance. 0 is a rubber stamp. |
| AutoMetrics | 48 metrics plus generated criteria, fitted to under 100 labels. Up to +33.4% Kendall. |
| pass@k, pass^k | At least one of k succeeds. All k succeed. Report k and n. |
pythonfrom math import comb def judge_pair(task, a, b, ask): # ask(task, first, second) -> float, + favors first margin = (ask(task, a, b) - ask(task, b, a)) / 2 # both orders: the position bonus cancels return "a" if margin > 0 else "b" if margin < 0 else "tie" def kappa(verdicts, labels): # lists of 0/1 n = len(labels); po = sum(v == y for v, y in zip(verdicts, labels)) / n pj, ph = sum(verdicts) / n, sum(labels) / n pe = ph * pj + (1 - ph) * (1 - pj) return (po - pe) / (1 - pe) if pe < 1 else 1.0 def pass_at_k(n, c, k): return 1 - comb(n - c, k) / comb(n, k) # n tries, c passes def pass_hat_k(n, c, k): return comb(c, k) / comb(n, k)
Now press Present or Teach and explain from memory. Cover the three grader types, the four judge formats, the two biases with their fixes, and pass@k against pass^k. Then go back to the hero and switch on the four fixes. Say which error each one removes.
This lesson re-teaches Lecture 15 of Stanford CS 329Z, Engineering AI Agents (Fall 2026), taught by Diyi Yang, Michael Ryan and John Yang. The course site is cs329z.stanford.edu and the slides are the lecture 15 PDF. The slides carry the lecture’s numbers. The explanations, toy models and devices are our own.