Error analysis: from raw failures to a failure taxonomy

Study time
≈ 2 h (estimate)
Needs
L2-M05-L03
Updated
2026-11-04

Progress is saved in this browser only. No account, nothing is sent to a server.

Draft · reviewed by AI, not yet by a person. Content may change. English translation: AI-assisted, not human-reviewed.
On this page

Module: L2-M05 · Duration: ~120 min (estimate, including the independent exercise) · Previous: L03 · Next: L2-M06-L01 (module RAG Fundamentals and Evaluation, not yet written)

1. Introduction

Many earlier lessons ended with the sentence "a small sample read by a person is needed": a metric function cannot read a negation, a code check lets through a reply that writes the answer in words, a judge only raises a flag. This lesson teaches what the reader does with that sample: error analysis is reading the failed replies, recording what went wrong, grouping the notes into a failure taxonomy, counting each category and deciding what to fix first. A good taxonomy turns "the system often gets it wrong" into a list of concrete jobs, and in turn it must also have its reliability measured like any human label (L02).

The failure notes, the two coders (the people who assign categories) and the true causes in the lab are all simulated; HocVui Tutor is a fictional product. The output of this lesson is a failure taxonomy built from notes, with the count table, the reliability check and the priority order.

2. Learning objectives

  1. Build a failure taxonomy from free-text notes and apply it with explicit rules. Practice: §8.2 part A, §9 (TODO 1).
  2. Run the lint on the taxonomy and state what the lint does not see (a taxonomy that is unfinished, a large "other" bucket). Practice: §8.2 part A, §8.4.
  3. Count by category (Pareto) and estimate the share with an interval, telling the share within the failure sample from the failure rate of the system. Practice: §8.2 parts B, E, §9 (TODO 3).
  4. Measure the reliability of the taxonomy with two coders and kappa. Practice: §8.2 part C, §8.3.
  5. Decide when to stop reading with a saturation check and state its limits. Practice: §8.2 part D, §9 (TODO 2).

3. Prerequisites and tools

  • L2-M05-L01: stratified sampling. L2-M05-L02, L03: kappa, adjudication, a versioned guideline. L2-M01-L04: the Wilson interval.
  • The code lab code-labs/l2-m05 (self-contained, needs only pytest). Data: failures.jsonl (60 notes, simulated) and two taxonomies taxonomy_v1.json, taxonomy_v2.json.

4. Concepts

4.1 From raw failures to a taxonomy

Anthropic writes that you will not know whether a grader works well "unless you read the transcripts and grades from many trials", so they read transcripts regularly; reading by hand "builds intuition for failure modes" but takes time, does not scale, and different readers give different signals [R1] (the quotes from Anthropic come from the automatic summary of the page-reading tool). Hamel Husain, in a blog post based on consulting experience (not peer-reviewed research), describes a process: read real conversations, write open notes about undesirable behaviour, build a taxonomy of failure types, then label each row and count the frequency (he uses an LLM for the taxonomy-building step; this lab does not); he calls error analysis the most valuable activity in AI development, a judgment based on his own experience, not on figures presented [R2].

The lesson's process: (1) choose the sample of failures to read (L01: it can be stratified); (2) for each failure write one free-text note about what went wrong, without assigning a category; (3) group similar notes into categories; (4) write a definition, a decision rule and examples for each category; (5) reapply to all the notes, count, check reliability and reread the cases that do not match.

Error analysis flow: raw failures (failing replies) → a free-text note for each failure → group into categories and write definitions and examples → apply the rules to every note → is the other bucket small and do two coders agree? Not yet: go back to grouping. Yes: count by category and choose what to fix.
Diagram: From raw failures to a taxonomy

4.2 A usable taxonomy

The lab's taxonomy requires: a unique category name that does not use "other" (a name reserved for what could not be classified); each category has a definition (at least 5 words), the keywords that apply and example ids; a precedence order (precedence) listing every category exactly once to decide when a note matches several categories; no keyword used in two categories; and each example must really be assigned to its own category by the rules. Each failure has one primary category; a note that mentions two causes is decided by the precedence rule, with the list of matches kept for a person to review (multi_match_ids).

A category should point to something fixable: "wrong calculation" suggests improving reasoning or the calculation tool; "tone" suggests fixing the system prompt. Too few categories lump different jobs together; too many leave each with one or two cases. The right size is a decision, there is no formula.

4.3 A taxonomy also needs reliability

If two people read the same note and assign different categories, the taxonomy is not yet usable, like any guideline (L02). How to measure: have two coders assign categories to the same failures, compute nominal kappa, then read the cases that differ. Artstein and Poesio recommend reporting the confusion matrix to see whether the disagreement is in the rarely seen categories [R3, §5.3]. The classification criteria themselves can also change as the reader sees more data: Shankar and colleagues describe "criteria drift", needing criteria to grade but grading again helping to define the criteria [R4, abstract only], so the taxonomy needs a version number like the guideline of L03.

5. Technical deep dive

5.1 Applying a taxonomy by keywords, and the lab's two versions

taxonomy.assign(note, tax) normalises the note to NFC and lowercase, splits it into words, and looks for keywords as whole words, contiguous (a multi-word phrase must be in the right order). If one category matches it takes that category; if several match it takes the one earlier in precedence; if none, "other". This is a way to apply a taxonomy a person wrote, not a replacement for reading the failures to build it.

On the 60 simulated HocVui Tutor notes, version 1 has four categories with single-word keywords ("sai", "tính", "đáp số", "trả lời", roughly "wrong", "calculate", "answer", "reply"). Result: 15 of 60 notes (0.250) fall into "other" (notes about words that are too hard, an invented rule and some truncated replies), 4 notes match several categories, and the kappa between the v1 assigner and coder 1 is 0.609. Visible errors: the note "Nêu một quy tắc sai" (roughly, "States a wrong rule") matches "sai" and is put into "tính sai" (wrong calculation); the note "Câu trả lời bị cắt" (roughly, "The reply is cut off") matches "trả lời" and is put into "lạc đề" (off topic). The lint does not see these errors: version 1 passes lint_taxonomy with 0 problems, because each keyword belongs to only one category. Version 2 has seven categories, with keywords that are phrases of two to three words: "other" is 0, 6 notes match several categories, and the kappa between the v2 assigner and coder 1 is 0.820. The figure 0.820 measures the assigner against coder 1 on the very notes used to write v2, so it tends to be high; the reliability of the taxonomy between people is the kappa of 0.646 between coder 1 and coder 2 (part C of the demo).

5.2 Counting, Pareto, intervals and saturation

The counts under version 2 (16, 11, 9, 8, 7, 6, 3 for wrong_result, gives_answer_away, tone, too_hard_for_grade, off_topic, invented_rule, truncated). pareto sorts from most to least with the cumulative share: the first three categories already account for 0.60 and the first five for 0.85. rates_with_ci gives each category its share in the sample and a Wilson interval: gives_answer_away is 11 of 60 = 0.183, interval 0.106 to 0.299. That is a share among the failures seen, not the failure rate of the system: estimating the latter requires knowing the failure rate of the traffic and how the failure sample was drawn (L01); the parameter population (the number of failing replies the sample was drawn from) only rules out a value smaller than the number of failures already seen.

saturation splits the notes into batches of 10 in id order and counts the new categories in each batch: (10 notes, 6 categories, 6 new), (20, 6, 0), (30, 7, 1), (40, 7, 0), (50, 7, 0), (60, 7, 0). The seventh category appears only in batch three: if you stop after 20 notes because "one batch had no new category" you would have missed it; with the rule "two consecutive batches with no new category" you must read to 50 and you catch it. Saturation is a sign, not proof; a rare category may still not have appeared. The stopping rule needs an additional criterion about the risk of failures not yet seen.

5.3 The blind spots of the assigner and of the counts

A keyword assigner does not understand negation: "Không bịa ra quy tắc nào." (roughly, "Does not make up any rule.") still matches the keywords of invented_rule (a test pins this). Nor does it understand synonyms or new phrasing: the §9 exercise gives a second set of notes with phrasing the first set did not use, to expose a taxonomy that memorised. The counts only speak about the failure sample you have; a category that is common in traffic but hard to detect will be undercounted.

6. The QA perspective

6.1 What this taxonomy does not prove

  • The counts come from 60 simulated notes, not the frequency in real traffic. A fix order by count does not yet take severity into account: a rare but harmful category may need fixing first.
  • Two coders agreeing (kappa 0.646 in the lab) does not say the taxonomy is right, only that it is repeatable; read the cases that differ as in L03.
  • A low share of "other" may come from keywords that are too broad. Read a random few of the assigned notes to check.
  • A taxonomy built from one sample will fit that sample best: keep a set of notes not used to build it and check there once.

6.2 Operations

Record the taxonomy version, the number of notes read and how the failure sample was drawn, the share of "other", the kappa between two coders, and the cases that match several categories. Anthropic treats reading transcripts as a periodic habit [R1]; an old taxonomy that nobody updates will put new failures into "other" or the wrong category. A rising share of "other" is a signal to reread and add categories.

7. Real-world scenarios

Scenario 1 (fictional): "A quarter is other". The HocVui Tutor team counted failures with four keywords and reported "wrong calculation is the most common category" (17 of 60). They found 15 notes falling into "other" and the notes about an invented rule wrongly put into "wrong calculation". They reread the notes, added three categories, switched to keyword phrases, and the "wrong calculation" figure dropped to 16 while "other" went to 0.

Scenario 2 (fictional): "Stopping after a clean batch". The team built a taxonomy from the first 20 notes and stopped because the second batch had no new category. They found that the seventh category (a reply cut off mid-way) appears only in the third batch (notes 21 to 30). They added a rule: stop only after at least two consecutive batches with no new category, and keep a check set not used for building.

8. Hands-on tutorial

8.1 Setup

cd academy-content/code-labs/l2-m05
python3 -m venv .venv && source .venv/bin/activate     # Windows: .venv\Scripts\activate
python -m pip install -r requirements.txt
python -m pytest            # 71 passed

8.2 Run the demo

python -m lab.demo l04

Output (copied from a real run on Python 3.14.6 and 3.12.14, 2026-11-04; the two versions give identical output). Every note, coder and cause is simulated:

A. 60 failure notes, taxonomy v1 (4 categories) then v2 (7 categories) (simulated annotators)
   v1: lint 0 problems; other 0.250; multi-match notes 4; kappa with coder 1 0.609
   v2: lint 0 problems; other 0.000; multi-match notes 6; kappa with coder 1 0.820
B. Pareto of taxonomy v2: [('wrong_result', 16, '0.27'), ('gives_answer_away', 11, '0.45'), ('tone', 9, '0.60'), ('too_hard_for_grade', 8, '0.73'), ('off_topic', 7, '0.85'), ('invented_rule', 6, '0.95'), ('truncated', 3, '1.00')]
C. two coders on the same 60 failures: kappa 0.646
D. saturation, batches of 10 in id order (items, categories, new): [(10, 6, 6), (20, 6, 0), (30, 7, 1), (40, 7, 0), (50, 7, 0), (60, 7, 0)]
E. gives_answer_away: 11 of 60 = 0.183, Wilson 95% (0.106, 0.299) (share of the reviewed failures, not a failure rate of the system)
   blind spot: 'Không bịa ra quy tắc nào.' -> invented_rule

Reading the output: A compares the two taxonomy versions (0 lint problems in both, but "other" 0.250 against 0.000; the kappa of the assigner with coder 1 is 0.609 and 0.820); B is the Pareto; C is the kappa between the two coders (0.646); D is the saturation check; E is the share with an interval for one category and the negation blind spot.

8.3 Try it yourself

Save it as try_l04.py in the lab's root folder (next to lab/), run python try_l04.py, then delete the file:

from lab import agreement as A, taxonomy as T

tax = {"precedence": ["a", "b"], "categories": [{"name": "a", "keywords": ["tính sai"]}, {"name": "b", "keywords": ["đáp số"]}]}
print(T.assign("Tính sai và lộ đáp số.", tax), T.assign("Học sinh saigon", tax))
print(T.saturation(["a", "b", "a", "c", "a", "a", "a"], batch=2))
print(A.cohen_kappa(["a", "b", "a", "c", "a"], ["a", "b", "b", "c", "a"]))

Output (identical on Python 3.14.6 and 3.12.14):

('a', ['a', 'b']) ('other', [])
[(2, 2, 2), (4, 3, 1), (6, 3, 0), (7, 3, 0)]
11/16

Reading: the note matches both categories so it takes a by precedence and the match list is kept; a note with no keyword gets "other". Line 2 is (number seen, number of categories, number of new categories): the first batch has two new categories, batch two adds c, the last two batches add none. Line 3: two coders assigning categories to five notes agree on 4 of 5; kappa is 11/16 (p_o = 4/5, p_e = 9/25), computed the same way as part C of the demo.

8.4 Run the lesson's tests

python -m pytest tests/test_l04_taxonomy.py tests/test_data.py -v

Result: 15 passed (10 tests for this lesson, 5 data checks). Read test_keywords_match_whole_tokens_and_contiguous_phrases, test_lint_cannot_see_that_the_v1_taxonomy_is_unfinished, test_lint_taxonomy_each_check and test_v2_counts_multi_match_notes_and_the_known_blind_spot. The tests run on in-memory values and the lab's simulated data; they check no taxonomy outside the lab.

8.5 Troubleshooting

Symptom Cause Fix
ValueError: precedence does not list a matching category precedence is missing a category List every category exactly once (the lint reports it)
The lint reports keyword ... used by two categories A keyword is in two categories Use a longer phrase or move it to one category
The lint reports example ... is assigned to another category The rules assign the example to a different category Fix the example or the keywords
ValueError: population smaller than the number of reviewed failures The "population" is smaller than the number of failures seen Use the real number of failures in the traffic

9. Independent exercise

Problem: Build a failure taxonomy for a reading-summary feature (simulated), check it on notes not yet seen, write a stopping rule for reading and choose what to fix first.

Requirements: complete exercises/test_l04_taxonomy.py:

  1. TODO 1: TAXONOMY (in the format of data/taxonomy_v2.json) with exactly one category for each expert label in the dev set (40 notes). It must pass lint_taxonomy on dev, "other" no more than 1/10 and kappa with the expert not below 7/10 on dev; on the test set (30 notes, with phrasing that dev does not use): "other" no more than 1/5 and kappa not below 3/5.
  2. TODO 2: write saturation_point(labels, quiet): the number of items read when the last new category (not counting "other") appears, provided at least quiet items with no new category follow; None if the sequence ends too early or is empty; ValueError when quiet is less than 1.
  3. TODO 3: TOP_TWO_SHARE (a Fraction): the share of all 70 notes that the two most frequent expert categories make up; and PRIORITY_NOTE: at least 30 words saying which category you will fix first and why, using the counts.

Test data: exercises/ex_failures_dev.jsonl, exercises/ex_failures_test.jsonl (each line id, note, expert).

Deliverable: the variable TAXONOMY, the function saturation_point, the variables TOP_TWO_SHARE and PRIORITY_NOTE in the file exercises/test_l04_taxonomy.py itself.

Acceptance criteria: python -m pytest exercises/test_l04_taxonomy.py passes (4 tests). The tests check the lint, "other" and kappa on dev and test, the function on small sequences, the share recomputed from the data, and only count the words of PRIORITY_NOTE: the reasoning is for a reviewer. A taxonomy that copies whole sentences of dev as keywords will pass dev but fail test.

Hint: start by reading the 40 dev notes and grouping them; write keywords by meaning (short distinctive phrases) and not by a single sentence; look at test only when dev passes. For TODO 2, try it first on a few sequences of your own with a few elements.

10. Knowledge check

0/16 done · Results are kept in this browser only.

P02 · True or false

lint_taxonomy returning 0 issues for a taxonomy means that taxonomy is complete and usable.

P04 · Select all that apply

Select everything the keyword assigner assign does not do.

P05 · Put in order

Put the process of building a failure taxonomy in order.

  1. Group similar notes into categories
  2. Write a definition, a decision rule and examples for each category
  3. Choose a sample of errors to read
  4. Reapply to every note, count, check reliability and reread the cases that do not match
  5. Write a free-text note for each error

P06 · Match

Match the function of lab/taxonomy.py with what it does.

P07 · Spot the bug

The function below copies saturation from the lab but has one bug: a batch consisting only of "other" notes is counted as having a new category.

def saturation(labels_in_order, batch=10):
    seen, out = set(), []
    for start in range(0, len(labels_in_order), batch):
        chunk = labels_in_order[start:start + batch]
        new = set(chunk) - seen
        seen |= new
        out.append((start + len(chunk), len(seen), len(new)))
    return out

P08 · Short answer

On 60 simulated notes, the kappa between the v1 assigner and coder2 is 0.484, between the v2 assigner and coder2 is 0.763; the kappa between the two coders coder1 and coder2 is 0.646. Why does 0.763 not yet prove v2 right, and which number is the reliability of the taxonomy?

P09 · Essay

Write 5-8 sentences: with taxonomy v2 on 60 simulated notes, wrong_result has 16 notes (0.267; Wilson 0.171 to 0.390) and gives_answer_away has 11 (0.183; Wilson 0.106 to 0.299). A manager wants to fix wrong_result first because there are more. Answer with an argument.

P11 · Recall

Lesson: L2-M05-L03

A team wrote taxonomy v2 after reading 60 notes and wants to know whether it is better than v1. By L03, which way of measuring is sensible?

P12 · Recall

Lesson: L2-M01-L04

With taxonomy v2, tone has 9 notes out of 60 (0.150) and a 95% Wilson interval from 0.081 to 0.261. What does that interval say?

P13 · Multiple choice

The Pareto of version 1 (simulated): wrong_result 17, other 15, gives_answer_away 11, tone 9, off_topic 8 out of 60 notes. What do the first three rows add up to cumulatively, and what is notable?

P14 · True or false

Version 2 has an "other" rate of 0.000, so the keywords have been proven to classify correctly.

P15 · Select all that apply

Before choosing what to fix first from a Pareto table, besides the counts, select everything you need to look at.

P16 · Multiple choice

The note "Câu trả lời bị cụt và không trả lời câu hỏi." ("The answer is cut off and does not answer the question.") (simulated) with taxonomy v2: what does assign return, and what should you do?

11. Summary

  • Concepts: error analysis is reading real failures, free-text notes, building a taxonomy, counting; a taxonomy has definitions, keywords, examples and a precedence order; it also needs reliability between two people and a version.
  • Skills: applying a taxonomy with contiguous keywords, lint, Pareto, the Wilson interval, the saturation check, kappa between two coders.
  • Traps: single-word keywords, a large "other" bucket, trusting a passing lint, stopping reading early, reading the counts of a sample as the frequency in the system, memorising notes.
  • You can now: receive a table of "the most common failure categories" and ask: where the notes came from, how much is "other", whether two people agree, whether the taxonomy was checked on notes not used to build it.

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-04 WebFetch (automatic summary): reading transcripts, understanding failure modes
R2 A Field Guide to Rapidly Improving AI Products (Husain) Hamel's Blog https://hamel.dev/blog/posts/field-guide/ 2026-11-04 WebFetch; an experience-based blog, not peer-reviewed: the error analysis process
R3 Inter-Coder Agreement for Computational Linguistics (Artstein and Poesio, 2008) Computational Linguistics https://aclanthology.org/J08-4004.pdf 2026-11-04 Full-text PDF: §5.3 reporting the confusion matrix
R4 Who Validates the Validators? (Shankar et al., 2024) arXiv:2404.12272 https://arxiv.org/abs/2404.12272 2026-11-04 Abstract only; a preprint, not recorded as peer-reviewed

Key terms (English ↔ Vietnamese)

English Tiếng Việt
Error analysis Phân tích lỗi (đọc lỗi thật để biết cái gì sai)
Failure taxonomy Phân loại lỗi
Open note Ghi chú mở (ghi chú tự do, chưa gán loại)
Precedence Thứ tự quyết (khi một ghi chú khớp nhiều loại; khác "thứ tự ưu tiên sửa")
Coder Người gán loại (hai người cùng gán loại cho các lỗi để đo độ tin cậy)
Pareto Bảng Pareto (xếp loại từ nhiều đến ít, cộng dồn tỷ lệ)
Saturation Bão hòa (đọc thêm không còn thêm loại mới)
Other bucket Phần "other" (ghi chú chưa gán được loại)