Module: L3-M04 · Duration: ~120 minutes (estimate, including the independent exercise) · Previous: L02 (reference trajectories and matching rules) · Next: L04
1. Introduction
The L02 matcher only knows the paths a person wrote. It cannot say which step of an unknown path is reasonable: cautious asks about one more book, right or wasteful? self_praise borrows without checking, but its thought says "checked". A step judge scores each tool call on a scale of 1 to 5, so that paths missing from the reference can still be assessed.
This lesson reuses the method of L2-M04 (a simulated judge, human labels, kappa, choosing a threshold, bias probes) for each step of a trajectory. The lab's judge is a simulated program: a fixed checklist plus three biases the lab author invented for teaching and deterministic noise. It is not a model, and its numbers say nothing about any real judge.
2. Learning objectives
- Describe the four checklist items of the simulated judge and state their blind spots. Read: §4.1.
- Read the judge's raw output with
parse_ratingand handle an unreadable output without counting it as a pass or a fail. Practice: §8.2 (part A), §8.3 (line 3). - Compute the confusion matrix, agreement, kappa and false-accept rate on human labels, and sweep thresholds on the dev split. Practice: §8.2 (part B), §8.3 (line 7).
- Explain why the threshold is chosen by a person and reported on the test split. Practice: §8.2 (parts C, F), §8.3 (lines 8, 9).
- Run bias probes and read the stability over repeats. Practice: §8.2 (parts D, E). Read: §6.1.
- Compute kappa by hand and propose a threshold under a stated requirement. Practice: §9.
3. Required knowledge and tools
- L2-M04-L01 to L2-M04-L04 (judges, verdict format, biases, calibration and kappa), L02 (counted calls). Code lab
code-labs/l3-m04. The lab copies the verdict parser and the agreement functions from the L2-M04 lab and does not import from it. - Separating the meanings. A step judge scores one tool call in the context of the steps before it; the judge of L2-M04 scores one answer to a question. The threshold here: a score at or above it means the judge calls the step good. The positive class is "good step": fp is a bad step let through, so the false-accept rate = fp / (fp + tn) and the false-reject rate = fn / (fn + tp), as in L2-M04-L04. The lab's "self-claim" bias (a thought with words such as "verified", "definitely") differs from self-preference of L2-M04-L03 (Zheng et al. call it self-enhancement): a judge favouring answers generated by its own model [R1]. The gate of L3-M03-L03 is not used in this lesson; it comes back in L05.
- The old policy still stands: no model call. The judge only scores; the lab only suggests a threshold; a person chooses the threshold and decides what the judge may be used for.
4. Concept explanations
4.1 How the simulated judge scores a step
For the tool-call step at position index, features computes four checklist items (0 or 1) from that step and the steps before it:
- C1 reached: the call counted (status
applied,failed,blockedorduplicate, arguments one JSON object). - C2 on_task: every book, student and note named in the arguments belongs to the task (first choice, second choice, student, note name).
- C3 new: no earlier call asked exactly this (same tool, same arguments, idempotency key ignored).
- C4 grounded: the step's precondition is in the record:
borrow_book Xafter aget_book Xthat said available and not after aLIMIT;save_note Tafter a successful borrow of T;send_noticeafter a saved note and not afterAPPROVAL_REQUIRED.
Utility U = 40·C1 + 20·C2 + 20·C3 + 20·C4, plus three biases and noise; score = (U + 10) // 20, clamped to 1 to 5. Without biases and noise, a step that passes all four items gets 5, one that misses exactly one of C2, C3, C4 gets 4. The three biases are parameters invented for teaching, so that a probe has a known truth to compare with: w_len (points for a longer thought), w_claim (15 points when the thought claims success), w_pos (10 points for the first two steps). Noise (±4) and format errors (3 percent) come from SHA-256 of (run id, index, repeat), never from the thought. The FAIR configuration turns off all three biases, the noise and the format errors.
The output is raw text "(SIMULATED) Step 1: C1=1 C2=1 C3=1 C4=0. Rating: [[5]]". parse_rating reads every [[...]] token: no token, or two different tokens, give ERROR; [[?]] gives UNKNOWN (an honest abstention); otherwise an integer 1 to 5. An unreadable verdict is never defaulted to a pass or a fail.
Three sources read on 2026-11-04 give the shape of this work. Zheng et al. study model judges and name position, verbosity and self-enhancement biases, as well as limited reasoning ability [R1]. Anthropic's article advises calibrating model graders closely with human experts, giving the judge a way out such as returning "Unknown" when it lacks information, and grading each dimension with an isolated judge rather than one judge for all dimensions [R2]. The lab follows all three: calibration on human labels, [[?]] as UNKNOWN, and a step judge that scores each step on its own.
4.2 Calibrating on human step labels
data/step_labels.json holds 30 step labels (15 good, 15 bad), each pointing at one step of one run, split dev/test 15/15. The labels were written by the lab author acting as a fictional reviewer, each with a short reason ("borrows without checking and says it checked"). The procedure is that of L2-M04-L04:
label_itemsasks the judge once per labelled step; unreadable outputs are dropped and listed.sweepcomputes tp, fp, fn, tn, raw agreement, kappa, false-accept and false-reject rates for thresholds 1 to 5 on dev.suggest_threshold(rows, cap)suggests the threshold with the highest kappa among those whose false-accept rate is at mostcap; a tie goes to the stricter one; it returnsNonewhen no threshold qualifies (say so, do not loosen the cap).- A person writes the threshold into
data/judge_policy.jsonwith a name and a reason;policy_thresholdrefuses a missing name, a missing reason, or a machine word as the name (auto,ci,script,judge,default). - Report on test, the split never used for choosing.
Cohen's kappa κ = (p_o − p_e) / (1 − p_e), where p_o is the raw agreement and p_e the probability of chance agreement computed from the data [R3]. The Wikipedia page on kappa quotes Bakeman et al.: no one value of kappa can be regarded as universally acceptable [R3]. So the threshold is chosen by consequence: in the lab, a bad step let through costs more than a good step flagged, so the cap is on the false-accept rate.
5. Technical deep dive
5.1 lab/stepjudge.py and lab/calibrate.py
features(task, tr, index): the four checklist items; raisesValueErrorwhen the step is not a tool call (the final answer is not judged).SimStepJudge(**overrides):utilityandjudgealso takethoughtandas_indexfor probes;make_configrefuses unknown keys and negative numbers.judge_run(judge, task, tr, threshold, retries=1): scores every tool-call step; anERRORis asked again once with the next repeat index (a new simulated draw), anUNKNOWNis not; what is still unreadable goes tounreadable, never tobelow.probe(judge, items, change): changes something that should not matter (padadds neutral sentences to the thought,claimadds a self-claim,latejudges the step as if it were step 9) and counts scores up, same, down. A fair judge shows a change of 0; a change other than 0 shows a sensitivity, not its cause in a real judge.confusion,raw_agreement,chance_agreement,cohens_kappa,false_accept_rate,false_reject_rate: exact fractions,Nonewhen the denominator is 0 (kappa isNonewhen p_e = 1).consistency(judge, labels, runs, tasks, repeats=3): the share of steps that get the same verdict in all three repeats, over the steps readable all three times. Stable does not mean right.label_itemsraises when a label points at a run or a step that does not exist: a label set that does not match the records is a broken set, not a smaller one.
6. QA perspective
6.1 What the judge and the calibration do not say
- The lab's biases are invented parameters; the probes find them because they were planted. On a real judge, a probe only shows a sensitivity, not its cause [R1].
- 30 labels from one fictional reviewer, 15 per split. Change one label and the rates jump; do not read 14/23 as a measurement.
- On this label set the judge never fails a good step (fn = 0 at every threshold): every error is a false accept. A false-reject rate of 0 does not make a good judge.
- The checklist does not know the order of preference: a step that lends the second choice while the first is free passes all four items (h22), and so does a note for a loan made to the wrong student (h30). Even the
FAIRjudge lets these two through: biases are not the only source of error. - The judge does not read the final answer and never sees the end state. It is one view, not the evaluator (L05).
7. Real-world scenarios
Scenario 1 (fictional): "Self-praise buys a score". On t01, self_praise borrows B001 without calling get_book, and its thought says "I have verified that B001 is available". C4 is 0. The FAIR judge gives 4, under the threshold 5; the default judge gives 5 thanks to the self-claim and position biases. QA sees this in the claim probe (the mean score rises by 1/4) and writes in the report: a step the judge passes is not trusted alone.
Scenario 2 (fictional): "CI sets its own threshold". A script proposes writing threshold 3 into judge_policy.json with chosen_by: "ci" to get fewer flags. policy_threshold refuses. QA re-runs the sweep and shows the owner: at threshold 3 the false-accept rate on dev is 5/6. The owner keeps threshold 5 and writes the reason.
8. Hands-on tutorial
8.1 Setup
cd academy-content/code-labs/l3-m04
python3 -m venv .venv && source .venv/bin/activate # Windows: .venv\Scripts\activate
python -m pip install -r requirements.txt
python -m pytest # 125 passed
8.2 Run the demo
python -m lab.demo l03
Output (copied from a real run on Python 3.14.6 and 3.12.3 (Linux), 2026-11-04; both versions give identical output). The judge and every agent are simulated:
A. one SIMULATED judgment: t01/self_praise step 1 (borrows without get_book, says it checked)
thought: 'I have verified that B001 is available, so borrowing it is definitely correct.'
features={'reached': 1, 'on_task': 1, 'new': 1, 'grounded': 0}
default judge: (SIMULATED) Step 1: C1=1 C2=1 C3=1 C4=0. Rating: [[5]]
fair judge: (SIMULATED) Step 1: C1=1 C2=1 C3=1 C4=0. Rating: [[4]]
parse: 4 ERROR UNKNOWN ERROR
B. 30 human step labels (15 good, 15 bad), split dev/test 15/15
default judge, dev split (unreadable dropped: ['h07', 'h23']):
t tp fp fn tn agreement kappa false_accept false_reject
1 7 6 0 0 7/13 0 1 0
2 7 6 0 0 7/13 0 1 0
3 7 5 0 1 8/13 14/79 5/6 0
4 7 4 0 2 9/13 7/20 2/3 0
5 7 3 0 3 10/13 14/27 1/2 0
suggestion with a false-accept cap of 1/10: None; with a cap of 1/2: 5
fair judge, dev split (unreadable dropped: []):
t tp fp fn tn agreement kappa false_accept false_reject
1 8 7 0 0 8/15 0 1 0
2 8 6 0 1 3/5 8/53 6/7 0
3 8 6 0 1 3/5 8/53 6/7 0
4 8 5 0 2 2/3 32/107 5/7 0
5 8 1 0 6 14/15 32/37 1/7 0
suggestion with a false-accept cap of 1/10: None; with a cap of 1/2: 5
C. the threshold a person chose (data/judge_policy.json): 5, by Lan, QA lead (fictional)
default judge on the test split at 5: n=15 {'tp': 7, 'fp': 3, 'fn': 0, 'tn': 5} agreement=4/5 kappa=14/23 false_accept=3/8 false_reject=0
bad steps let through: ['h18', 'h22', 'h30']
fair judge on the test split at 5: n=15 {'tp': 7, 'fp': 2, 'fn': 0, 'tn': 6} agreement=13/15 kappa=14/19 false_accept=1/4 false_reject=0
bad steps let through: ['h22', 'h30']
D. bias probes over the 30 labelled steps (the same step, a change that should not matter)
pad default: up=6 same=22 down=0 dropped=2 mean=3/14 | fair: mean=0
claim default: up=7 same=21 down=0 dropped=2 mean=1/4 | fair: mean=0
late default: up=0 same=27 down=1 dropped=2 mean=-1/28 | fair: mean=0
E. consistency over 3 repeats (default judge): 20 of 26 readable steps = 10/13
F. a threshold set by 'ci' is refused: a person must be named in chosen_by
Reading the output: part A: step 1 of self_praise misses C4; the default judge gives 5, the fair judge 4; the parse line is four cases of parse_rating (one token, two different tokens, [[?]], no token). Part B: the default judge has two unreadable outputs on dev (h07, h23), leaving 13 items. At every threshold fn = 0; the highest kappa and the lowest false-accept rate are both at threshold 5 (14/27 and 1/2). No threshold meets the false-accept cap 1/10, so the suggestion is None; with a cap of 1/2 the suggestion is 5. The fair judge at threshold 5 has kappa 32/37 and false-accept rate 1/7. Part C: a person chose 5. On test, the default judge lets three bad steps through (h18, h22, h30), the fair judge two (h22, h30). Part D: a neutral sentence raises 6 steps, a self-claim 7 steps, judging as step 9 lowers 1 step; the fair judge does not move. Part E: 26 steps are readable all three times, 20 get the same verdict. Part F: a threshold set by "ci" is refused.
8.3 Try it yourself
Save as try_l03.py in the lab's root folder (next to lab/, not inside lab/), run python try_l03.py, then delete the file:
from fractions import Fraction
from lab import calibrate as C, data, evaluator as V, stepjudge as J
tasks = {t["id"]: t for t in data.load_tasks()}
judge, fair = J.SimStepJudge(), J.SimStepJudge(**J.FAIR)
for tid, agent in (("t02", "no_verify"), ("t01", "wrong_book")):
t = tasks[tid]
tr = V.run_task(t, agent)["trajectory"]
for i in J.tool_steps(tr):
f = J.features(t, tr, i)
print(tid, agent, i, tr["steps"][i - 1]["action"]["tool"], "".join(str(v) for v in f.values()),
J.parse_rating(judge.judge(t, tr, i)), J.parse_rating(fair.judge(t, tr, i)))
c = {"tp": 7, "fp": 3, "fn": 0, "tn": 5}
po = Fraction(c["tp"] + c["tn"], sum(c.values()))
pe = Fraction((c["tp"] + c["fp"]) * (c["tp"] + c["fn"]) + (c["fn"] + c["tn"]) * (c["fp"] + c["tn"]), sum(c.values()) ** 2)
print(po, pe, (po - pe) / (1 - pe), C.cohens_kappa(c), C.false_accept_rate(c))
for who in ("Lan, QA lead (fictional)", "auto"):
try:
print(C.policy_threshold({"threshold": 4, "chosen_by": who, "reason": "test"}))
except ValueError as exc:
print("refused:", exc)
Output (Python 3.14.6 and 3.12.3, Linux, identical):
t02 no_verify 1 borrow_book 1110 5 4
t02 no_verify 2 borrow_book 1110 4 4
t02 no_verify 3 save_note 1111 ERROR 5
t01 wrong_book 1 get_book 1111 5 5
t01 wrong_book 2 borrow_book 1111 5 5
t01 wrong_book 3 save_note 1111 5 5
4/5 22/45 14/23 14/23 3/8
4
refused: a person must be named in chosen_by
Reading: each of lines 1 to 6 is the task, agent, step, tool, the four checklist items C1 to C4, the default judge's score and the fair judge's score. Lines 1 and 2: no_verify borrows without checking (C4 = 0); the fair judge gives 4 to both steps, the default judge gives step 1 a 5 (position bias plus noise). Line 3: the default judge returns an unreadable output (ERROR); judge_run would ask once more. Lines 4 to 6: wrong_book lends the second choice while the first is free, yet every step passes all four items: the order-of-preference blind spot. Line 7: kappa by hand from the default judge's test matrix: p_o = 4/5, p_e = 22/45, κ = 14/23, equal to cohens_kappa; false-accept rate 3/8. Lines 8 and 9: a threshold with a person's name and a reason is accepted; "auto" is refused.
8.4 Run the lesson tests
python -m pytest tests/test_l03_stepjudge.py -v
Result: 34 passed. Read test_blind_spot_the_checklist_does_not_know_the_order_of_preference, test_self_praise_buys_a_pass_from_the_default_judge, test_unreadable_verdicts_are_re_asked_once_then_listed_apart_never_counted and test_the_threshold_must_come_from_a_named_person.
8.5 Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
TypeError: every score must be an int |
ERROR or UNKNOWN passed to rows_at |
Drop unreadable outputs first and report how many were dropped, as label_items does |
suggest_threshold returns None |
No threshold meets the false-accept cap | Report that the judge does not meet the requirement; do not loosen the cap to get a number |
ValueError: a person must be named |
chosen_by is empty or a machine word |
A person reads the sweep and writes a name and a reason into judge_policy.json |
9. Independent exercise
Problem: 16 fictional steps already have a simulated judge's score and a human label. The team's requirement: "the highest kappa among thresholds whose false-accept rate is at most 1/4; a tie goes to the higher threshold".
Requirements: complete exercises/test_l03_judge.py:
- TODO 1:
AT_4: the matrix{tp, fp, fn, tn}at threshold 4, andKAPPA_4: kappa there as a string such as"3/8". Compute by hand first. - TODO 2:
THRESHOLD: the threshold you propose to the person who decides, andREASON: one sentence that names the false-accept rate you accept.
Test data: exercises/ex_labels.json.
Deliverable: the four variables above, in the file exercises/test_l03_judge.py itself.
Acceptance criteria: python -m pytest exercises/test_l03_judge.py passes (2 tests), recomputed with lab.calibrate; REASON must contain the exact false-accept rate of the threshold you chose.
Hints: TODO 1: write tp, fp, fn, tn first, then p_o and p_e as in §8.3. TODO 2: filter by the false-accept cap first, then compare kappa; the threshold with the highest agreement or kappa over the whole table may not pass the cap.
10. Knowledge check
0/8 done · Results are kept in this browser only.
P02 · True or false
P04 · Select all that apply
P05 · Spot the bug
A colleague writes a function that collects per-step scores for a report. Their report shows the judge "failing" a step that a person called good. Find the defect.
from lab import stepjudge as J
def scores(judge, task, tr):
out = {}
for i in J.tool_steps(tr):
s = J.parse_rating(judge.judge(task, tr, i))
out[i] = s if isinstance(s, int) else 1
return outP06 · Put in order
P08 · Recall
Lesson: L2-M04-L0411. Summary
- Concepts: a step judge scores one call in context; an unreadable output is a separate thing; calibrate on human step labels, sweep on dev, report on test [R2][R3]; a bias is a sensitivity to something that should not matter [R1].
- Skills: run
features,judge,parse_rating,sweep,suggest_threshold,probe,consistency; compute kappa by hand. - Pitfalls: trusting a self-praising thought; counting
ERRORas a fail or a pass; choosing the threshold by agreement; letting a machine set the threshold; reading 30 labels as a measurement; thinking a fair judge is enough. - You can now: take a step judge and ask: what it checks and what it does not, how far it agrees with people on a split not used for choosing, who chose the threshold and why, and what it is sensitive to that should not matter.
12. References
| ID | Title | Publisher | URL | Accessed | Relevance |
|---|---|---|---|---|---|
| R1 | Judging LLM-as-a-Judge with MT-Bench and Chatbot Arena (arXiv 2306.05685) | arXiv (Zheng et al.) | https://arxiv.org/abs/2306.05685 | 2026-11-04 | Read the abstract page and the passages of the HTML version on position, verbosity and self-enhancement biases; experiments not read |
| R2 | Demystifying evals for AI agents | Anthropic | https://www.anthropic.com/research/demystifying-evals-for-ai-agents | 2026-11-04 | Read the page text: calibrate model graders with human experts, the "Unknown" way out, an isolated judge per dimension |
| R3 | Cohen's kappa | Wikipedia | https://en.wikipedia.org/wiki/Cohen%27s_kappa | 2026-11-04 | Read the definition (p_o, p_e) and the part on interpreting magnitude (quoting Bakeman et al.); open encyclopedia |
Glossary (English ↔ Tiếng Việt)
| English | Tiếng Việt |
|---|---|
| Step judge | Judge cấp từng bước: chấm một lời gọi tool trong ngữ cảnh các bước trước; ở lab là chương trình mô phỏng |
| Unreadable verdict (ERROR, UNKNOWN) | Phán quyết không đọc được: không có hoặc có hai token khác nhau / tự nhận không biết; không bao giờ là đạt hay trượt |
| Human step label | Nhãn bước của người: tốt hay xấu, kèm lý do |
| False accept rate / false reject rate | Tỷ lệ lọt: bước xấu bị cho qua / tỷ lệ oan: bước tốt bị đánh trượt |
| Bias probe | Thăm dò thiên lệch: đổi một điều không nên ảnh hưởng và đo điểm thay đổi |