Module: L2-M03 · Duration: ~120 min (estimate, including the independent exercise) · Previous: L03 · Next: L05
1. Introduction
"Answer quality" is really several separate things: is the answer correct, is it relevant to the question, is it complete, is it consistent across runs, and when the system answers from a document, is it faithful to the document and grounded (can it say where it got the information)? Each word sounds obvious until two graders reach two conclusions.
This lesson teaches you to write an operational definition for six criteria: what input is needed, what counts as passing, examples that pass and fail, and what it is easily confused with. The lab implements a deterministic check for each criterion and shows that the six criteria are six separate dimensions (none follows from another, except that grounded implies faithful): an answer can be correct but not faithful, faithful but wrong, correct but incomplete. The output is a set of operational definitions with examples, and the understanding that each check is only a proxy with blind spots.
2. Learning objectives
- Write an operational definition for a criterion, made of the input, the definition, examples and the confusable criterion. Practice: §8.2 part A and exercise §9.
- Run and check correctness, relevance, completeness and consistency, and state the blind spots of each. Practice: §8.3 and
test_relevance_completeness_and_consistency_boundaries. - Distinguish faithfulness from groundedness with operational definitions and examples. Practice: §8.2 part B.
- Measure the "unsupported claim" check against human labels, and point out the cases where it falsely flags and the cases where it misses. Practice: §8.2 part C.
- Refuse to grade when a required input is missing. Practice: §8.3 (
MissingInput).
3. Prerequisites and tools
- L2-M01-L02: quality criteria, operational definitions, risk levels.
- L2-M03-L01 and L03: the number-finding function, the precision and recall of a metric, rubrics. L1-M06: repeating a case (the basis of consistency).
- The code lab
code-labs/l2-m03(self-contained). RAG (generating an answer supplemented by retrieved documents) is taught in L2-M06; here we only use the idea "a system that answers from a few passages of a document".
4. Concepts
4.1 An operational definition has four parts
A criterion is not usable until you can state four things. The input needed: what the criterion compares the answer with (a gold answer, a list of required points, a document passage, other runs). The definition: one sentence saying what counts as passing. Examples that pass and fail. The confusable criterion: how it differs from the criterion nearest to it. lab/criteria.py records all four in CRITERIA; test_every_criterion_has_inputs_definition_and_a_confusable asserts that each criterion has them all.
The input that is most often overlooked, and that decides whether you can grade at all: faithfulness needs the document, correctness needs a gold answer, consistency needs several runs. If the dataset lacks that column, the criterion does not exist for that record. Anthropic reminds us that a criterion must be "Relevant" to the purpose of the application, for example "Strong citation accuracy might be critical for medical apps but less so for casual chatbots" [R3]: choosing criteria is a product-specific decision (§6.3).
4.2 Correct and relevant
Correctness in the lab is a narrow version: the answer states the gold answer, which is a number (correctness(reply, gold) uses contains_number from L01). For the tutor of L2-M01, "correct" for the work-checking feature means the conclusion (right or not yet right) is correct; two definitions for one word, so record which applies to which dataset. The blind spots inherited from L01: negation, hedged answers, numbers written in words.
Relevance asks whether the answer talks about what was asked, regardless of right or wrong. relevance(reply, topic_terms) requires the answer to contain at least one topic term set by the case writer (such as ["nhân"] (multiply) for "6 nhân 4 bằng bao nhiêu?", what is six times four) ; a multi-word term (such as nhân tử) must have all its words in the answer, and matching is by word so 24 does not match inside 124. The check is useless if the terms are too generic ("là", "số": "is", "number") and it misses synonyms.
4.3 Complete and consistent
Completeness checks whether the answer covers every required point. You write a list of points, each point being a set of interchangeable phrases ([["6 nhân 4", "thương nhân với số chia"], ["24"]]). completeness(reply, points) returns the fraction of points covered (a Fraction) and the list of indexes of missing points. Against bypasses: an empty list of points, or a point with no phrases, is rejected (otherwise every answer would be "complete"), and phrases match on word boundaries (24 does not match inside 124).
Consistency checks whether the same question gives the same answer across several runs. consistency(answers) is the fraction of pairs of runs whose answers are equal. With [24, 24, 25] there are three pairs, one of them equal: 1/3. At least 2 runs are needed, and "no answer" (None) is equal to nothing, not even another None: otherwise a system that never answers would be perfectly consistent. Consistent does not mean correct: a system can be wrong in the same way every time.
5. Technical deep dive
5.1 Claims and faithfulness
Faithfulness asks whether what the answer asserts is supported by the document given to the system. We define it per claim (a checkable assertion). The documentation of Ragas, a RAG evaluation library, describes faithfulness as "how factually consistent a response is with the retrieved context", computed by splitting the answer into claims, checking whether each claim can be inferred from the context, then dividing the number of supported claims by the total number of claims (the example in the documentation: an answer with two claims, one supported, a score of 0.5) [R2]. The original paper says Ragas is a framework for evaluating RAG without reference answers labelled by humans [R1] (only the abstract was read).
criteria.faithfulness(reply, sources) implements exactly that ratio formula but checks with a deterministic rule instead of a model: it splits the answer into sentences (each sentence is a claim, a simplification), then checks each sentence. It returns (the fraction supported, the list of unsupported claims). An answer with no claims is rejected; missing documents raise MissingInput.
5.2 Groundedness: citations and sources
"Faithfulness" and "groundedness" are often used interchangeably, and this lesson does not verify each tool's definition of groundedness. The lab uses the two words with two separate meanings, defined by the lab, so as to see two different errors:
- Faithful: each claim is supported by some passage of the document that was given.
- Grounded (as the lab defines it): each claim cites (
[S2], inside the sentence, before the full stop) at least one real source code, and a cited passage supports it. A citation after the full stop is split off as a separate claim with no content (lowgroundedness), so the check requires the citation to be inside the sentence.
criteria.groundedness returns the status of each claim: grounded, uncited (no citation), unknown_source (cites a code that does not exist) or unsupported_by_cited (cites a real passage but that passage does not support the claim). Result: a sentence is faithful but not grounded when it is right according to the document but does not say where (uncited) or cites wrongly (unknown_source, unsupported_by_cited). Conversely, a grounded claim is certainly faithful.
5.3 The claim-support check and its blind spots
claim_supported(claim, passage) treats a claim as supported when there exists one sentence of the passage meeting three conditions: every number in the claim appears in that sentence; at least 3/4 of the content words (not common words, not numbers) of the claim appear in that sentence; and the claim and the sentence agree on negation (both have or both lack không, chưa, chẳng). Comparing sentence by sentence rather than the whole passage avoids stitching together words from several sentences.
The lab runs this check on 13 fictional answers (26 claims) with a human label for each claim (data/rag_cases.jsonl, the passages in data/passages.json, a fictional "sách Toán 4" textbook). The positive class is "the claim is not supported" (the check raises a warning), the reverse of L01 where positive was "accepted". Result: tp 5, fp 1, fn 1, tn 19; precision 0.833 and recall 0.833. The two wrong cases are two named blind spots: G03 was wrongly flagged ("Phép nhân giao hoán nên 4 nhân 6 cũng bằng 24", which says that multiplication is commutative so four times six also equals twenty-four: correct in meaning according to the passage, but the word "giao hoán" is not in the document: a paraphrase is treated as unsupported), and G09 was missed ("Phép chia hết có số dư khác 0", a division with no remainder has a remainder other than zero, contradicts "số dư bằng 0", but almost all the words overlap and there is no negation to catch: an antonym slips through). This precision and recall are measured on 13 answers written by the lab; do not read it as quality on real text.
6. The QA perspective
6.1 The six criteria are six separate dimensions
The table below (demo part A) runs the six checks on six crafted answers; the checks' results match the human labels in all 36 cells.
| Answer | Correct | Relevant | Complete | Consistent | Faithful | Grounded | Note |
|---|---|---|---|---|---|---|---|
| X1 | yes | yes | yes | yes | yes | yes | All six hold |
| X2 | yes | yes | yes | yes | no | no | Correct, but the fact is not in the document that was given |
| X3 | no | yes | yes | yes | yes | yes | Faithful to a wrong document |
| X4 | yes | yes | no | yes | no | no | States the result, missing the checking step; "kết quả là 6" ("the result is six") is not in S5 |
| X5 | no | no | no | no | yes | yes | Faithful and grounded but off topic; there is no answer so it is not consistent (§4.3) |
| X6 | yes | yes | yes | no | yes | yes | Right this time but not stable across runs |
Three lessons: (1) correct does not imply faithful: X2 is a real RAG error, the system answers from its own knowledge instead of the document; (2) faithful does not imply correct: X3 is faithful to a wrong document and is still wrong, so the two checks do not substitute for each other; (3) a single "quality" number mixes errors of different kinds together: report each column separately.
6.2 No input, no grade
check_inputs(criterion, record) raises MissingInput if the record lacks (or has empty) a field the criterion needs, and profile(record) skips a criterion that lacks its input rather than guessing. This guards against a common mistake: running faithfulness on a record with no document and getting a "good" score because there is nothing to contradict. For a high-risk criterion, a missing input must stop the evaluation.
What the checks do not do: relevance does not understand synonyms; completeness depends on the phrases you write and does not understand negation ("không cần phép nhân, kết quả là 24", meaning "no multiplication needed, just the result", still matches the point "phép nhân"); consistency compares only the final answer, not the working; faithfulness and groundedness do not understand paraphrases, antonyms or claims that need two sentences. Each needs a small sample reviewed by a human (L2-M05).
6.3 Choosing criteria for each feature
No feature needs all six. HocVui Tutor in hint mode does not use documents: there is no faithfulness, and the main criterion is pedagogy (do not state the answer, L2-M01). The "answer from the textbook" mode needs faithfulness and groundedness, and if the student can click through to the source then groundedness is a product requirement. The process: list the criteria (L2-M01-L02), ask what input each criterion needs and whether the dataset (L2-M02) has that column yet, assign risk, then choose a deterministic check, a rubric (L03) or a human. A criterion with no input gets dropped.
7. Real-world scenarios
Scenario 1 (fictional): "Correct, but from where?". HocVui's "answer from the textbook" mode scored 100% correctness. Once they turned on faithfulness, they saw many answers like X2: the system answered correctly from its own knowledge because the retrieved passage did not contain the information. High correctness hid a retrieval error. They reported two columns and added the grounded criterion.
Scenario 2 (fictional): "The check reports clean". A team used the deterministic faithfulness, saw 1.00 for every answer about division, and considered the criterion met. A manual reviewer found "Phép chia hết có số dư khác 0" (a division with no remainder has a nonzero remainder): it contradicts the document but the check let it through, exactly case G09. They added a small human-reviewed sample for answers with negation or antonyms and recorded the limitation.
8. Hands-on tutorial
8.1 Setup
cd academy-content/code-labs/l2-m03
python3 -m venv .venv && source .venv/bin/activate # Windows: .venv\Scripts\activate
python -m pip install -r requirements.txt
python -m pytest # 63 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-03; the two versions give identical output):
A. six crafted replies, six criteria (checker verdicts equal the human truth on all 36 cells)
id corre relev compl consi faith groun
X1 yes yes yes yes yes yes all six hold
X2 yes yes yes yes no no correct but not faithful: the fact is not in the given source
X3 no yes yes yes yes yes faithful to a wrong source, so not correct
X4 yes yes no yes no no correct but incomplete
X5 no no no no yes yes faithful and grounded but off topic
X6 yes yes yes no yes yes right this time, but not stable across runs
B. faithfulness and groundedness of 13 replies that were given the passages listed
G01 faithfulness 1.00 groundedness 1.00 ['grounded', 'grounded']
G02 faithfulness 1.00 groundedness 0.00 ['uncited', 'uncited']
G03 faithfulness 0.50 groundedness 0.50 ['grounded', 'unsupported_by_cited']
G04 faithfulness 0.50 groundedness 0.50 ['grounded', 'unsupported_by_cited']
G05 faithfulness 1.00 groundedness 1.00 ['grounded', 'grounded']
G06 faithfulness 1.00 groundedness 0.50 ['unsupported_by_cited', 'grounded']
G07 faithfulness 1.00 groundedness 0.50 ['unknown_source', 'grounded']
G08 faithfulness 0.50 groundedness 0.50 ['unsupported_by_cited', 'grounded']
G09 faithfulness 1.00 groundedness 1.00 ['grounded', 'grounded']
G10 faithfulness 0.50 groundedness 0.50 ['grounded', 'unsupported_by_cited']
G11 faithfulness 0.50 groundedness 0.50 ['unsupported_by_cited', 'grounded']
G12 faithfulness 0.50 groundedness 0.50 ['grounded', 'unsupported_by_cited']
G13 faithfulness 1.00 groundedness 1.00 ['grounded', 'grounded']
C. 'unsupported claim' detector vs human labels on 26 claims: {'tp': 5, 'fp': 1, 'fn': 1, 'tn': 19}
precision 0.833 recall 0.833 wrong on [('G03', 'flagged', 'supported'), ('G09', 'missed', 'contradicted')]
Reading the output:
- A. Six answers, six different profiles (the five-letter abbreviated columns follow the order of §6.1).
- B.
G02is faithful at 1.00, grounded at 0.00 (no citation);G06cites the wrong passage;G07cites a code that does not exist;G09gets 1.00 on both although it contradicts the document. - C. 26 claims; the check is wrong on
G03(a false flag) andG09(a miss).
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 criteria, data
src = {"S3": data.load_json("passages.json")["S3"]}
reply = "Một giờ có 60 phút. Một phút có 60 giây [S9]. Một ngày có 24 giờ [S3]."
print(criteria.faithfulness(reply, src))
print(criteria.groundedness(reply, src))
print(criteria.completeness("Ra 24.", [["6 nhân 4"], ["24"]]))
print(criteria.consistency([24, 24, 25]), criteria.consistency([None, None]))
try:
criteria.check_inputs("faithfulness", {"reply": reply, "sources": {}})
except criteria.MissingInput as e:
print("MissingInput:", e)
Output (identical on Python 3.14.6 and 3.12.14):
(Fraction(1, 1), [])
(Fraction(1, 3), [('Một giờ có 60 phút.', 'uncited'), ('Một phút có 60 giây [S9].', 'unknown_source'), ('Một ngày có 24 giờ [S3].', 'grounded')])
(Fraction(1, 2), [0])
1/3 0
MissingInput: faithfulness needs ['reply', 'sources']; missing ['sources']
Reading: all three sentences are faithful (ratio 1) because they all appear in S3, but only the third is grounded (1/3): the first has no citation, the second cites S9, which does not exist. completeness gets 1/2 and points out that the point at index 0 is missing. [None, None] gives 0, not 1.
8.4 Run the lesson's tests
python -m pytest tests/test_l04_criteria.py -v
Result: 8 passed. Read test_the_six_profiles_show_that_criteria_are_independent and test_checkers_against_human_claim_labels_and_their_blind_spots.
8.5 Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
MissingInput: faithfulness needs [...] |
The record lacks the document | Add sources; this is intended behaviour |
ValueError: every point needs at least one non-empty phrase |
A list of points has an empty part | Each point must have at least one phrase |
| Low faithfulness for an answer that is right in meaning | A paraphrase does not match on words | This is a blind spot (§5.3); have a human look |
9. Independent exercise
Problem: Write the required points for grading the completeness of an answer to the question "Làm sao kiểm tra kết quả của phép chia 24 cho 4, được 6?" (how do you check the result of dividing twenty-four by four, which gives six?), then find where the faithfulness check disagrees with a human.
Requirements: complete exercises/test_l04_criteria.py and exercises/my_points.json:
- TODO 1: fill in
my_points.json(at least two points, each a list of interchangeable phrases). A complete answer must have two points: (1) it states how to check by multiplying back, (2) it compares the result with the dividend.completeness == 1must be true for exactly the answers labelled complete inrecords.jsonand false for the others. - TODO 2: fill in
DIFFER: the ids (sorted) of the records inrecords.json["faith"]for whichcriteria.faithfulness(...)[0] == 1differs fromhuman_faithful. - TODO 3: fill in
FAITHFUL_NOT_GROUNDED: the ids (sorted) of the records whose faithfulness is 1 but whose groundedness is less than 1.
Test data: exercises/records.json (8 answers for TODO 1 with a truth_complete label; 7 records for TODO 2 and 3, each with a document passage and a human_faithful label; the document passages are in data/passages.json).
Deliverable: the filled-in my_points.json and the two lists.
Acceptance criteria: python -m pytest exercises/test_l04_criteria.py passes (3 tests); no TODO is left in my_points.json. The test only requires classifying the 8 answers correctly; it does not know whether your phrases are natural.
Hint: an answer that states the result but has no checking step is not complete: point (1) must demand the checking step, not just the number. List the many ways people say "multiply back". For TODO 2, run faithfulness on each record first and then compare with the labels; the two disagreeing cases are two different kinds of blind spot, so be able to say which kind.
10. Knowledge check
0/18 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 function below is meant to implement consistency but it has a bug that makes a system that never answers be reported as perfectly consistent. Find the bug.
def consistency(answers):
pairs = [(a, b) for i, a in enumerate(answers) for b in answers[i + 1:]]
agree = sum(a == b for a, b in pairs)
return agree / len(pairs)P08 · Short answer
Write a four-part operational definition for the relevance criterion for the question "Một giờ có bao nhiêu phút?" ("How many minutes are in an hour?") with the check relevance(reply, topic_terms).
P09 · Essay
HocVui adds a "answer from the textbook" mode (passages S1 to S5) and wants to choose criteria. Write 5-8 sentences: which criteria to choose, what input each needs in the dataset, and how you report the results.
P10 · Recall
Lesson: L2-M03-L01P11 · Recall
Lesson: L2-M01-L02P12 · Multiple choice
P13 · Fill in the blank
P14 · True or false
P15 · Select all that apply
P16 · Multiple choice
P17 · Multiple choice
11. Summary
- Concepts: each criterion has an input, a definition, examples and a confusable criterion; faithful means each claim is supported by the document, grounded means each claim cites the right source; the six criteria are separate.
- Skills: checking the six criteria; refusing when an input is missing; measuring a check against human labels.
- Traps: merging six dimensions into one number; believing correct implies faithful; letting
NoneequalNone; reading a deterministic check as understanding meaning. - You can now: state the input each criterion needs and the kinds of answers your check will let through.
12. References
| ID | Title | Publisher | URL | Accessed | Relevance |
|---|---|---|---|---|---|
| R1 | Ragas: Automated Evaluation of Retrieval Augmented Generation (Es et al.) | arXiv | https://arxiv.org/abs/2309.15217 | 2026-11-03 | Abstract-only: a multi-dimension RAG evaluation framework, needing no human labels |
| R2 | Faithfulness (Available metrics) | Ragas documentation | https://docs.ragas.io/en/stable/concepts/metrics/available_metrics/faithfulness/ | 2026-11-03 | Faithfulness defined as the fraction of claims supported by the context |
| R3 | Define success criteria and build evaluations (Develop tests) | Anthropic | https://platform.claude.com/docs/en/test-and-evaluate/develop-tests | 2026-11-03 | A criterion must be relevant to the purpose of the application (read 100,000 of 152,950 characters) |
Key terms (English ↔ Vietnamese)
| English | Tiếng Việt |
|---|---|
| Correctness | Độ đúng |
| Relevance | Độ liên quan |
| Completeness | Độ đầy đủ |
| Consistency | Độ nhất quán |
| Faithfulness | Độ trung thành với nguồn |
| Groundedness | Độ có căn cứ (mỗi mệnh đề trích dẫn đúng nguồn; nghĩa theo lab) |
| Claim | Mệnh đề (một khẳng định kiểm được) |
| Operational definition | Định nghĩa vận hành |
| Topic term | Thuật ngữ chủ đề |