Module: L2-M02 · Duration: ~90 min (estimate, including the independent exercise) · Previous: L02 · Next: L04
1. Introduction
A case is not usable until it has an expectation: what a correct answer looks like. An expectation comes in two forms. The first is a label: a person looks at a pair (question, system answer) and assigns "pass" or "fail". The second is a reference answer: you write in advance what the answer must contain or must not contain, so that code can grade it.
Both forms can be trusted only when another person, reading the same document, reaches the same conclusion. That document is the labelling guideline. This lesson teaches how to write a guideline, measure whether two people agree, fix the guideline when they disagree, and write a reference answer that code can check, together with its blind spot. The product of the lesson is a guideline with labelled examples.
2. Learning objectives
- Distinguish a label from a reference answer, and choose the suitable form for a criterion.
- Write a guideline with definitions, examples, counter-examples, rules for borderline cases (a borderline case sits between two labels, unlike the edge case of L02) and a policy for when unsure, then check the structure with a lint.
- Compute the raw agreement and the chance agreement between two annotators, and explain why the raw number is easy to misread.
- Run the loop disagreement → borderline-case rule → measure again, and handle the cases that still disagree with adjudication.
- Write a reference answer that code can check and state what it misses.
3. Prerequisites and tools
- L2-M01-L03: code, human and model graders; raw agreement and the confusion matrix.
- L2-M02-L01 and L02: sources and coverage. The cases that need labelling come from there.
- The code lab
code-labs/l2-m02. Cohen's kappa (the agreement coefficient corrected for chance) is taught in L2-M05-L02; this lesson uses only raw agreement and chance agreement.
4. Concepts
4.1 A label and a reference answer are two different things
A label is a person's judgment on a specific output: "does this answer reveal the result?". You need a label when you do not know in advance which answer is correct, or when several answers are correct. A reference answer is an expectation attached to the input, written before running the system: for example "must not contain the number 6" or "must mention the word math". It is cheap to rerun thousands of times but only catches what you already predicted.
Anthropic advises creating a reference solution for each task, "a known working output that passes all graders" [R1]: that is a sample output that has passed a check. The lab's reference answer differs in that it is an expectation (what the output must or must not contain), not a sample output. In the lab, a reference answer is a reference block with must_include, must_not_include and source (where the expectation comes from, so others can review the expectation itself).
4.2 What a guideline contains
A good guideline, following the lab's structure (data/guideline_v2.json), has:
- task: the question the annotator must answer, in one sentence.
- labels: each label has a definition, examples and counter-examples (look similar but are not).
- borderline_rules: the rule for when two labels both seem right. This is the part that decides agreement.
- unsure_policy: what to do when still unable to decide (record "unsure", hand it to the coordinator, do not guess).
The standard of a good task, according to Anthropic, is "two domain experts would independently reach the same pass/fail verdict", and "Ambiguity in task specifications becomes noise in metrics" [R1]. The guideline is how you turn that standard into something checkable. One group of cases deserves a special mention (detailed disagreement analysis: L2-M05-L03): cases where even people find it hard to agree (Anthropic lists "Ambiguous test cases where even humans would find it hard to reach an assessment consensus" among the edge cases to take into account) [R2]; the guideline must say how to handle them instead of letting each person decide.
5. Technical deep dive
5.1 Measuring with raw agreement and chance agreement
labeling.raw_agreement(a, b) is the share of items on which two people give the same label. It is easy to understand but easy to be fooled by: if 90% of items are "ok", two annotators labelling completely independently with that frequency still agree about 0.9 × 0.9 + 0.1 × 0.1 = 0.82. labeling.chance_agreement(a, b) computes this number from each person's label frequencies: Σ (frequency of label x for person A × frequency of x for person B). The test simulates 20,000 independent items with a 90/10 split and both numbers come out near 0.82.
So an "agreement of 0.82" can be nothing at all. The kappa coefficient, which normalises the gap between these two numbers, is taught in L2-M05-L02. This lesson stops at always reporting both numbers side by side, and reporting by group (clear cases, borderline cases) to see where the disagreement sits.
5.2 The loop: disagreement, borderline-case rule, measure again
The lab has 80 fictional items (an exercise question, a tutor answer) and two guidelines for the same job: label ok (does not reveal the result) or leak (reveals it). Guideline v1 says only "leak is the tutor stating the result". Guideline v2 adds a rule: the result appearing in any form, including inside a check question ("em thử xem 6 nhân 4 có bằng 24 không?") or a guess, or written in words, is a leak.
The result (demo B): with v1, the two people agree at 0.787 (chance agreement 0.496), of which borderline cases only 11 of 22. With v2: 0.950 (chance 0.545), borderline cases 22 of 22. An important limit: the two "annotators" are simulated; with v1, the lab makes them label borderline cases like a coin toss, and with v2 makes them wrong 4% of the time on every case. The loop is illustrated by construction, not measured on real people. What you take away is the process: measure, find the disagreeing cases, write a rule for exactly that kind of case, measure again on new items if you can.
5.3 A reference answer that code can check, and its blind spot
labeling.check_reply(reply, ref) returns a list of errors: a missing must_include entry, or a must_not_include entry that is present. Two important details. First, it uses a whole-number match: if "6" is forbidden, then "16 viên" or "6.5" is not flagged, while "được 6 viên." is flagged. A substring match would wrongly flag "16". Second, the blind spot: numbers written in words ("sáu"), numbers with a thousands separator ("1.000"), full-width digits and other phrasings are not caught.
Demo C runs the "does not contain the result" check over all 80 items and compares it to the adjudicated label: it differs on 4 of 80, all 4 being sentences that write the result in words ("Đáp số là sáu đó em"). This shows both the value and the limit: the code check matches the human label on 76 items, but a student (or a model) who gets around it with words slips through. The fix is not to patch the regex endlessly but to understand that it is a cheap filter and to keep a sample for people to look at (L2-M05).
6. The QA perspective
6.1 Adjudication and who is responsible for the final label
When two people disagree, a third person (or a short meeting) must decide; this is called adjudication. labeling.resolve keeps to a strict rule: if two people agree, it takes the shared label; if not and there is no adjudicated label yet, it raises an error and does not silently pick a side (demo D: 17 disputed items with v1). Two things QA must keep: record who adjudicated and under which rule, and feed the new rule back into the guideline so it does not have to be decided again.
Another risk: guideline examples leaking into the dataset. If an annotator (or a model acting as judge) sees an example that matches a case to be graded, the label is no longer independent. labeling.examples_in_dataset lists the examples that match cases in the dataset; the result must be empty. The function only normalises letter case and whitespace: an example that matches a case but is typed without diacritics, or differs by one "?", is not seen.
6.2 What the lint does not check, and how to report
lint_guideline catches: a missing task, fewer than two labels, a missing definition, examples or counter-examples, empty examples or counter-examples, the same example under two labels, missing borderline-case rules, a missing unsure policy. The lab's guideline v1 has exactly two problems: no borderline_rules and no unsure_policy. But a passing lint does not mean two people will label the same way; only measuring agreement on real items proves that. A counter-example of one label may be an example of the other (v2 does this with the sentence "thử xem 6 nhân 4..."), so the lint only flags it when the examples of two labels coincide.
A good labelling report states: the number of annotators and how they were chosen; raw and chance agreement, overall and by group; the number of adjudicated cases; the guideline version. Do not report a single "label quality" number.
7. Real-world scenarios
Scenario 1 (fictional): "Two people, two readings". The team labelled result leaks with a one-line guideline. Two people agreed at 0.787; on the 22 borderline cases (like "em thử xem 8 nhân 2 có bằng 16 không?") they matched on only 11. The team almost concluded "the model is hard to grade" when the fault was in the guideline: it did not say whether a check question containing the result counts as a leak.
Scenario 2 (fictional): "The automatic check already matches". The team wrote a "does not contain the result" check and saw it match the human label on 76 of 80 items, so it dropped the human review step altogether. A month later, a parent reported the tutor wrote "đáp số là sáu". A code check does not catch numbers written in words; the 4 differing items in the demo had said so in advance.
8. Hands-on tutorial
8.1 Setup
cd academy-content/code-labs/l2-m02
python3 -m venv .venv && source .venv/bin/activate # Windows: .venv\Scripts\activate
python -m pip install -r requirements.txt
python -m pytest # 73 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.14, 2026-11-03; the two versions give identical output):
A. lint of the two guidelines
guideline_v1.json: 2 problem(s)
- no borderline_rules: say what to do when two labels both seem to fit
- unsure_policy is empty: say what an annotator does when unable to decide
guideline_v2.json: 0 problem(s)
B. two annotators, 80 items, before and after the guideline fix
guideline v1: agreement 0.787 chance agreement 0.496
by category {'borderline': (11, 22), 'leak': (25, 27), 'ok': (24, 27), 'words': (3, 4)}
guideline v2: agreement 0.950 chance agreement 0.545
by category {'borderline': (22, 22), 'leak': (25, 27), 'ok': (26, 27), 'words': (3, 4)}
C. a reference check ('must not contain the answer') against the adjudicated label
disagrees with the label on 4/80 items:
('L078', 'words', 'Đáp số là ba đó em.')
('L077', 'words', 'Đáp số là sáu đó em.')
D. a disputed item with no adjudicated label is never settled silently
17 disputed items; resolve() -> KeyError: 'item L066 is disputed and has no adjudicated label'
Reading the output:
- A. Guideline v1 has 2 problems; v2 has none.
- B. Raw agreement 0.787 then 0.950; borderline cases 11/22 then 22/22; the cases with the result written in words are still 3/4 in both (a sample of 4, do not read too much into it).
- C. The code check differs from the label on 4/80 items, all numbers written in words (the demo prints only two).
- D. 17 disputed items;
resolverefuses when the adjudicated label is missing.
8.3 Measure a small pair of labels yourself
Save as try_l03.py inside the lab folder:
from lab import labeling
g = {"task": "Phản hồi có xác nhận nhầm không?",
"labels": {"ok": {"definition": "Không xác nhận.", "examples": ["Chưa đúng."], "counter_examples": ["Đúng rồi."]},
"bad": {"definition": "Xác nhận nhầm.", "examples": ["Đúng rồi."], "counter_examples": ["Chưa đúng."]}},
"borderline_rules": [], "unsure_policy": ""}
print(labeling.lint_guideline(g))
a = ["ok", "ok", "bad", "ok", "bad", "ok"]
b = ["ok", "bad", "bad", "ok", "ok", "ok"]
print(labeling.raw_agreement(a, b), round(labeling.chance_agreement(a, b), 3))
print(labeling.confusion(a, b))
ref = {"must_not_include": ["6"], "source": "policy §1"}
print(labeling.check_reply("Đáp số là 16 viên.", ref), labeling.check_reply("Đáp số là 6 viên.", ref))
Run python try_l03.py. Output:
['no borderline_rules: say what to do when two labels both seem to fit', 'unsure_policy is empty: say what an annotator does when unable to decide']
0.6666666666666666 0.556
{('bad', 'bad'): 1, ('bad', 'ok'): 1, ('ok', 'bad'): 1, ('ok', 'ok'): 3}
[] ['forbidden: 6']
Six items give a raw agreement of 0.667 and a chance agreement of 0.556: the gap is small, so at this size nothing can be concluded yet (this is also why you need many items). The last line: "16" is not flagged, "6" is flagged.
8.4 Run the lesson's tests
python -m pytest tests/test_l03_labelling.py -v
Result: 13 passed. Read test_two_independent_annotators_agree_by_chance_more_than_people_expect and test_a_reference_check_matches_the_label_except_for_numbers_written_in_words.
8.5 Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
ValueError: label lists must have the same length |
The two label lists differ in length | Align by id before comparing |
KeyError: item ... is disputed and has no adjudicated label |
A disputed case has not been adjudicated | Add an adjudicated label for that case |
check_reply does not flag the number you forbade |
The number is inside another number (16) or written in words | This is intended behavior; see §5.3 |
9. Independent exercise
Problem: Write a guideline for the label "the tutor wrongly confirms a student's incorrect answer" and measure the agreement of a pair of annotators.
Requirements: complete exercises/test_l03_guideline.py and exercises/my_guideline.json:
- TODO 1: fill in
my_guideline.json(labelsokandwrongly_confirmed) so thatlint_guidelineis empty, there are at least 3borderline_rules, and no example matches any question indata/eval_v1.jsonl. - TODO 2: fill in
AGREEMENTandCHANCE(rounded to 3 digits) for the label pair inannotations.json. - TODO 3: fill in
DISPUTED: the list of ids with different labels, in order.
Test data: exercises/annotations.json (20 fictional items, two annotators labelling ok or bad; bad corresponds to the label wrongly_confirmed in your guideline).
Deliverable: the filled-in my_guideline.json and the three variables.
Acceptance criteria: python -m pytest exercises/test_l03_guideline.py passes (2 tests); no TODO is left in my_guideline.json.
Hint: the borderline cases of this label are generic praise and "close enough"; write a rule for each kind. Use labeling.raw_agreement, chance_agreement, disagreements.
10. Knowledge check
0/14 done · Results are kept in this browser only.
P02 · True or false
P04 · Select all that apply
P05 · Put in order
P06 · Match
P07 · Spot the bug
The guideline below (shortened from guideline_v2.json, with one spot changed) makes lint_guideline report example 'Đáp số là 6.' is an example of both ok and leak. Find the bug.
{
"ok": {
"definition": "Câu trả lời không chứa đáp số cuối cùng dưới bất kỳ dạng nào.",
"examples": ["Em thử viết phép chia xem sao.", "Đáp số là 6."],
"counter_examples": ["Em thử xem 6 nhân 4 có bằng 24 không?"]
},
"leak": {
"definition": "Câu trả lời có viết đáp số cuối cùng bằng số hoặc bằng chữ.",
"examples": ["Đáp số là 6.", "Đáp số là sáu đó em."],
"counter_examples": ["Em thử viết phép chia xem sao."]
}
}P08 · Short answer
Two labellers label independently, and each gives 90% of items the label ok and 10% the label bad. Roughly what raw agreement do they reach by chance alone, and what does that say about a report of "agreement 0.82"?
P09 · Essay
The team labels "reveals the answer" with a one-line guideline and sees the two labellers agree at 0.787, then plans to conclude "the model is hard to grade". Write 5-8 sentences: what you check first, where the likely cause is, and how to fix it.
P10 · Multiple choice
P11 · True or false
P12 · Fill in the blank
P13 · Recall
Lesson: L2-M02-L0211. Summary
- Concepts: a label is a person's judgment on an output; a reference answer is an expectation written in advance that code can check; a guideline has definitions, examples, counter-examples, borderline-case rules and a policy for when unsure.
- Skills: measure raw and chance agreement, by group; the loop disagreement → rule → measure again; no silent adjudication; a reference answer with whole-number matching.
- Traps: trusting raw agreement when labels are skewed to one side; believing a passing lint means two people will match; believing a code check that matches people means people can be dropped.
- You can now: take a guideline and say whether it has borderline cases yet, measure it with two people, and know what your automatic check misses.
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 | Two independent experts reach the same verdict; reference solution; ambiguity becomes noise |
| R2 | Define success criteria and build evaluations (Develop tests) | Anthropic | https://platform.claude.com/docs/en/test-and-evaluate/develop-tests | 2026-11-03 | Ambiguous cases where even humans find it hard to agree (read the first 100,000 characters) |
Key terms (English ↔ Vietnamese)
| English | Tiếng Việt |
|---|---|
| Label | Nhãn |
| Reference answer | Đáp án tham chiếu |
| Labelling guideline | Hướng dẫn gắn nhãn |
| Counter-example | Phản ví dụ |
| Borderline case | Ca lưng chừng (ca nằm giữa hai nhãn) |
| Chance agreement | Độ đồng thuận do ngẫu nhiên |
| Adjudication | Phân xử ca bất đồng |
| Annotator | Người gắn nhãn |