Module: L2-M01 · Duration: ~100 min (estimate, including the independent exercise) · Previous: L02 · Next: L04
1. Introduction
After L02 you have a list of criteria. The next question: who or what will grade each criterion? There are three main choices: code (a function that matches, counts, checks), humans (reviewers read and assign labels) and a model (an LLM acting as the judge, called model-graded or LLM-as-a-judge). There is also the question of when to measure: offline (before release, on a fixed dataset) or online (on real traffic).
No choice wins on every axis. This lesson gives you a map of the trade-offs (speed, cost, reliability, sensitivity to meaning) and how to check the grader itself. The practical result is a table choosing the evaluation type for each of the tutor's criteria. The details of judges and of human evaluation are two separate modules (L2-M04, L2-M05); here we only need enough to choose correctly.
2. Learning objectives
- Compare the three grader types on speed, cost, reproducibility and sensitivity to meaning.
- Choose the right grader type for each criterion and explain the choice.
- Detect the blind spot of a code grader by running two graders side by side.
- Measure the agreement between a simulated judge and human labels, and read the confusion matrix.
- Distinguish offline and online evaluation, and explain why thumbs-down is not the error rate.
3. Prerequisites and tools
- L2-M01-L02: criteria,
risk,criterion_of. - L1-M04-L01: property-based oracles (the graders in the lab are those oracles).
- The code lab
code-labs/l2-m01. The judge, the human labels and the online feedback in the lab are all synthetic simulations, not measured from a real model or real users.
4. Concepts
4.1 Code-based graders
A code-based grader is a deterministic function: the input is the reply (and the case), the output is pass/fail with a reason. Anthropic lists the strengths as "Fast", "Cheap", "Objective", "Reproducible", and the weakness: "Brittle to valid variations that don't match expected patterns exactly" [R1]. Anthropic's eval guide also gives code-based examples such as exact match, similarity comparison and ROUGE-L [R2].
In the lab, the graders live in lab/graders.py: vi (has accented Vietnamese letters), max_words, no_leak, no_final_answer, verdict, facts,
redirect, no_echo, advises. They grade strings, not meaning. That is why they are fast and trustworthy within their scope,
and have blind spots outside it (§5.1).
4.2 Human evaluation
People read and assign labels according to guidelines. OpenAI writes: "Human judgment evals provide the highest quality but are slow and expensive" [R3]; Anthropic calls humans "Gold standard quality" but "Expensive" and "Slow" [R1]. We use humans when a criterion has no well-defined answer (tone, age appropriateness), and as the reference against which to check other graders.
Two things to remember when using people. One: two people do not always agree either. In the lab's synthetic label file, rater A and rater B agree on 52/60 samples (0.867). The final label
is the adjudicated one. Two: how the sample is chosen matters. The label file has 40 randomly chosen replies and 20 replies deliberately chosen from among the curt replies
(the stratum column), so 23/60 "curt" labels is not the real rate. A deliberately skewed sample is reasonable for checking a judge on a rare class, and cannot be used to estimate a rate.
4.3 Model-graded (LLM-as-a-judge)
A model is asked to grade another model's output against a rubric. OpenAI: using a model to grade "is cheaper to run and more scalable than human evaluation" [R3]. Anthropic: a model-based grader is "Flexible", "Scalable", "Captures nuance", but "Non-deterministic", "More expensive than code" and needs "calibration with human graders for accuracy" [R1].
An academic study of judges (Zheng et al., 2023) reports that a strong judge reaches over 80% agreement with humans, "the same level of agreement between humans", while also naming the biases "position, verbosity, and self-enhancement" [R4]. (This relies on the abstract only; the details of each bias will be covered in L2-M04.) Two messages: a judge can be usable, and you should not trust it before comparing it with human labels on your data.
4.4 Offline and online
- Offline evaluation: run the system on a fixed dataset before release, whenever the prompt, model or code changes. It is reproducible, can run in CI, and does not touch users. Anthropic: automated evals are especially useful "pre-launch and in CI/CD" [R1]. OpenAI recommends running evals "on every change" [R3].
- Online evaluation: use signals from real traffic (thumbs, abandonment rate, samples of replies reviewed by people). Anthropic describes production monitoring as "Reactive; problems reach users before you know about them", and A/B testing as "Slow; days or weeks to reach significance" [R1].
The two complement each other: offline blocks known defects before release, online detects what the dataset does not have. Online has its own trap, selection bias (§5.3): the people who leave feedback do not represent all users.
5. Technical deep dive
5.1 The blind spot of a code grader
The homework cases have two graders that address the same idea: no_leak looks for the correct answer in the reply, while no_final_answer looks for answer-style phrases ("đáp số", "kết quả là", "= 6"). A reply like
"Kết quả là 7." (a wrong number) gets past no_leak but is caught by no_final_answer. Running both on the 140 homework replies of tutor v1 (§8): no_leak catches 9, no_final_answer catches 12, the union of the two is 12.
If you only had no_leak, you would under-report 3 defects without knowing it. The lesson: a code grader is a hypothesis about how failures appear, and that hypothesis needs to be tested.
5.2 Human labels and the simulated judge
lab/human.py loads data/human_labels.jsonl (60 samples, criterion tone, two raters and one adjudicated label). lab/judge.py has SimulatedJudge, which is not an LLM: it computes from the reply's content plus a seeded random factor, and is deliberately made slightly biased: it likes long replies (close to the "verbosity" that [R4] names) and likes polite words such as "nhé" (this is a design choice of the lab, not a result of [R4]).
We compare the judge with the adjudicated label using raw agreement (the match rate) and a confusion matrix over the "curt" class (human.confusion): tp is curt and the judge caught it, fn is curt but the judge let it pass, fp is normal but the judge flagged it, tn is normal and the judge let it pass.
Result (§8): agreement 0.750 with tp=19, fp=11, fn=4, tn=26. The judge catches 19/23 curt replies, but also wrongly flags 11 normal replies. Raw agreement hides the shape of the errors; the confusion matrix does not. From the matrix we compute the precision of the "curt" flag: of the replies the judge flagged, how many are really curt (tp / (tp + fp)). Precision depends on the share of the rare class in the sample, so an oversampled sample gives a higher precision than a random one (you will compute this yourself in the exercise).
(L2-M05 will teach the kappa coefficient, which removes the agreement due to chance.)
5.3 Online feedback and selection bias
lab/online.py simulates 2000 sessions. Only a small share of users leave a thumb, and people who meet a faulty reply leave a thumb more often (30% versus 4%; numbers set by the lab, not measured). Result (§8): 169/2000 sessions have a thumb (response rate 0.085),
thumbs-down make up 0.645 of the sessions with a thumb, while the true share of faulty sessions is 0.190. The two numbers are far apart and both are correct, because they answer two different questions. Thumbs are a tripwire (an alarm) when they change abnormally, not an error rate.
6. The QA perspective
6.1 Choosing the grader type for each criterion
| Criterion | Type | Reason | Also needed |
|---|---|---|---|
| language, concision | code | Clear rule, computable | Tests for the grading function |
| pedagogy | code, two overlapping graders | The string signals are clear enough, but there is a blind spot | Run side by side, cross-check |
| safety | code, two graders for two ideas (no_echo, advises) |
Each idea is a string signal | Report each check separately |
| correctness (verdict) | code | Well-defined answer | Counter-examples (agreeing with a wrong answer) |
| tone | model, calibrated by humans (L02 tentatively recorded human; after this lesson we choose model, calibrated with human labels) |
Needs nuance, too many replies for humans to read them all | Human labels, confusion matrix |
| Everything after release | online | Sees what the dataset does not have | Treat as a tripwire |
Rule of thumb: code first, then a judge for what code cannot grade, and humans as the reference for both. Anthropic also recommends favoring volume: "More questions with slightly lower signal automated grading is better than fewer questions with high-quality human hand-graded evals" [R2], but that sentence never means skipping the check of the grader.
6.2 Checking the grader itself
- For a code grader: write tests with a passing reply, a failing reply and a "near-failing" reply (
test_no_leak_matches_the_whole_number_only: "16 viên" and "6,5" are not the answer 6). - For a judge: have a set of human labels, report the agreement and the confusion matrix, and state how the label set was sampled.
- For humans: measure the agreement between raters, and keep the labeling guidelines in writing (L2-M05).
- For online signals: state the response rate and who tends to respond.
7. Real-world scenarios
Scenario 1 (fictional): "the judge says 90% is fine". A team uses a judge to grade tone and reports "90% of replies are friendly". Nobody compared the judge with people. When they labeled 60 replies themselves, they found the judge missed most curt replies that included the word "nhé" (the judge likes polite words). The 90% figure measured the judge's preferences, not tone.
Scenario 2 (fictional): the online alarm. HocVui Tutor's thumbs-down share stayed steady around 60-65% after every release, so the team thought "users hate the tutor". After measuring the response rate (8.5%) and cross-checking against a sample of replies reviewed by people, they found 60-65% reflected who presses (people who meet a fault press more than people who meet a good reply; in the lab it is 30% versus 4%), not the error rate. What matters is when it changes: if a release pushes thumbs-down up to 80%, that is the signal to rerun the offline evaluation.
8. Hands-on tutorial
8.1 Run the demo
cd academy-content/code-labs/l2-m01
python -m lab.demo l03
Output (copied from a real run on Python 3.14.6 and 3.12.14, 2026-11-03; the two versions are identical):
A. code-based graders have blind spots: 140 homework replies, which check catches what
{'no_leak': 9, 'no_final_answer': 12, 'either': 12}
B. human labels (60 replies, tone)
raters A and B agree on 0.867
rude in the file: 23/60 (oversampled: not the real rate)
C. simulated judge against the adjudicated human label
raw agreement 0.750, confusion {'tp': 19, 'fp': 11, 'fn': 4, 'tn': 26}
D. online signal: 2000 simulated sessions
sessions: 2000
rated: 169
response_rate: 0.085
thumbs_down_share: 0.645
true_failure_rate: 0.190
Reading the output:
- A. The two graders address the same idea but do not catch the same set of replies.
no_leakmisses 3. - B. The two raters agree on 0.867; "curt" makes up 23/60 because the sample is oversampled.
- C. The judge matches the human label 75% of the time: not enough to replace humans, and it errs in a predictable way.
- D. Thumbs-down 0.645 versus the true failure rate 0.190.
8.2 Run the tests
python -m pytest tests/test_l03_graders.py -v
Result: 16 passed. Read test_the_blind_spot_of_no_leak_is_covered_by_no_final_answer and test_judge_agreement_with_humans_is_imperfect_and_pinned.
8.3 Try a new grader
Save it as try_l03.py in the lab's root folder (next to lab/):
from lab import graders
case = {"params": {"answer": "6"}}
for text in ("Kết quả là 7. Bạn chép lại nhé.", "Có 16 viên, hoặc 6,5 viên.", "Bài này dùng phép chia."):
print(f"{text!r:42} no_leak={graders.run_check('no_leak', text, case)!s:6} "
f"no_final_answer={graders.run_check('no_final_answer', text, case)}")
Output:
'Kết quả là 7. Bạn chép lại nhé.' no_leak=None no_final_answer=gives a final answer ('kết quả là')
'Có 16 viên, hoặc 6,5 viên.' no_leak=None no_final_answer=None
'Bài này dùng phép chia.' no_leak=None no_final_answer=None
None means the check passes. Line 1 shows the blind spot: no_leak passes a reply that states a wrong result.
8.4 Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
ValueError: grader 'facts' needs an argument |
The check needs a parameter | Write facts:[["tử số"]] or max_words:60 |
| Numbers differ from the lesson in part D | Different seed | Use seed=1 and 2000 sessions |
9. Independent exercise
Problem: Evaluate a judge honestly, and close a grader's blind spot.
Requirements: complete exercises/test_l03_judge_and_grader.py:
- TODO 1: compute the precision of
SimulatedJudge's "curt" flag (flag =tone_okisFalse; precision =tp / (tp + fp)) on the 40randomlabels and on all 60 labels, against the adjudicated label. Fill inPRECISION = {"random": ..., "all": ...}. - In a comment, explain why the two precisions differ (hint: the share of the "curt" class in each sample, see the paragraph on precision in §5.2).
- TODO 2: write
states_any_number(text)that returnsTruewhen the reply contains a standalone number (including1.000and3,5). The function must catch all 12 faulty replies of tutor v1 on the homework cases.
Test data: human.load(), judge.SimulatedJudge, human.confusion; four example strings in the test.
Deliverable: the completed test file, with the paragraph explaining the two precisions.
Acceptance criteria: python -m pytest exercises/test_l03_judge_and_grader.py passes (3 tests); precision on the random sample is much lower than on the whole file.
Hint: human.confusion(predicted, truth) returns tp, fp, fn, tn; to find a standalone number, use re lookbehind/lookahead so you do not cut in the middle of a number.
10. Knowledge check
0/18 done · Results are kept in this browser only.
P02 · True or false
P03 · Short answer
Why does "Kết quả là 7. Bạn chép lại nhé." (Vietnamese for "The result is seven. Please copy it down.") get past no_leak but get caught by no_final_answer, and what does that show about how to use graders?
P04 · Select all that apply
P05 · Fill in the blank
P06 · Put in order
P07 · Match
P08 · Spot the bug
A colleague writes a simple no_leak grader as below for the answer "6". It wrongly fails the reply "Có 16 viên, hoặc 6,5 viên." (Vietnamese for "There are sixteen pieces, or six and a half pieces."), which does not state the answer 6. Find the bug.
def no_leak(text, answer):
return None if answer not in text else f"states the answer {answer}"P09 · Short answer
Demo part D: thumbs-down make up 0.645 of the sessions with a thumb, while the true failure rate of sessions is 0.190. Explain why both are right.
P10 · Essay
Write 5-8 sentences: the plan for grading tone for HocVui Tutor, including the kind of grader, the human labels needed, and what the final number does not allow you to conclude.
P11 · True or false
P12 · Multiple choice
P13 · Select all that apply
P14 · True or false
P15 · Recall
Lesson: L2-M01-L02P16 · Recall
Lesson: L1-M04-L01P18 · Short answer
A team uses a judge to grade tone and reports "90% of replies are friendly" but has not compared the judge with humans. What do you ask for before accepting the number?
11. Summary
- Concepts: code-based is fast, cheap and reproducible but grades strings and has blind spots; humans are the reference but slow, expensive and do not always agree; model-graded is flexible and cheaper than humans, but non-deterministic, biased and needs calibration with human labels; offline blocks defects before release, online sees what the dataset does not have.
- Skills: choose the grader type for each criterion; run two graders side by side to find blind spots; read agreement and the confusion matrix; read online signals as a tripwire.
- Traps: trusting a grader that has not been tested; reporting a judge's number that has not been compared with humans; using an oversampled sample to estimate a rate; treating thumbs-down as the error rate.
- You can now: build a table choosing the evaluation type for a set of criteria and state how to check each grader.
12. References
| ID | Title | Publisher | URL | Accessed | Relevance |
|---|---|---|---|---|---|
| R1 | Demystifying evals for AI agents | Anthropic | https://www.anthropic.com/engineering/demystifying-evals-for-ai-agents | 2026-11-03 | Strengths/weaknesses of code, model and human graders; offline, production monitoring, A/B |
| R2 | Define success criteria and build evaluations (develop tests) | Anthropic | https://platform.claude.com/docs/en/test-and-evaluate/develop-tests | 2026-11-03 | Code-based examples; "automate when possible", volume versus quality |
| R3 | Evaluation best practices | OpenAI | https://developers.openai.com/api/docs/guides/evaluation-best-practices | 2026-11-03 | Three kinds of evaluator; continuous evaluation (page redirected from platform.openai.com) |
| R4 | Judging LLM-as-a-Judge with MT-Bench and Chatbot Arena (Zheng et al., 2023) | arXiv | https://arxiv.org/abs/2306.05685 | 2026-11-03 | A judge agrees with humans over 80% of the time; position, verbosity, self-enhancement biases. Abstract only |
Key terms (English ↔ Vietnamese)
| English | Tiếng Việt |
|---|---|
| Code-based grader | Bộ chấm bằng code |
| Model-graded / LLM-as-a-judge | Chấm bằng model / dùng LLM làm giám khảo |
| Human evaluation | Đánh giá bởi người |
| Offline / online evaluation | Đánh giá offline (trước phát hành) / online (trên lưu lượng thật) |
| Confusion matrix | Ma trận nhầm lẫn |
| Raw agreement | Độ đồng thuận thô (tỷ lệ khớp) |
| Selection bias | Thiên lệch chọn mẫu |
| Precision | Trong các reply bị gắn cờ, tỷ lệ thật sự đúng là lớp bị gắn cờ |
| Oversample | Lấy mẫu vượt tỷ lệ thật cho một lớp hiếm |