Module: L1-M06 · Duration: ~165 min (estimate, including the independent exercise) · Previous: L02 · Next: L04 - Regression after prompt or model changes
1. Introduction
To know whether a change makes the product better or worse, you need two fixed things: a set of questions that is used every time (the golden dataset), and a recorded point of comparison (the baseline). Without those two things, every comparison is a feeling.
This lesson teaches how to build a golden dataset for an LLM feature, where the right answer is not a fixed string, and how to record a baseline so that it can still be compared after many weeks.
2. Learning objectives
- Design a golden dataset case: the question, a property-based oracle, the source of the expectation, the risk level.
- Assess the quality of the dataset itself: an oracle that is too loose, too strict, an expectation that contradicts the source.
- Build a baseline that records the configuration, the number of runs, the seed and the fingerprint of the dataset.
- Explain why two runs can only be compared on the same dataset.
- Decide when a baseline must be rebuilt.
3. Prerequisites and tools
- L02:
run_case, the Wilson interval. - L1-M05-L05: golden transcripts (the same idea of "reviewed output", but here it is a pass rate).
4. Concepts
4.1 One case in a golden dataset
{"id": "Q-REFUND", "question": "Chính sách đổi trả thế nào?",
"oracle": {"facts": [["30 ngày"], ["kể từ ngày nhận hàng", "từ khi nhận hàng"]], "lang": "vi"},
"source": "policy §1", "risk": "high", "tags": ["refund"]}
In English: the question asks what the return policy is; the oracle requires the return period and, in a second group, either of two phrases saying that it counts from receipt of the goods.
| Field | Why it is needed |
|---|---|
oracle |
The properties of a correct answer, not a string (L01 section 4.4) |
source |
Where the expectation comes from. A reviewer can check the expectation itself |
risk |
Decides the threshold and the number of runs (L02) |
tags |
Filtering by feature when reporting |
Anthropic's documentation suggests considering consistency as well: "If a user asks the same question twice, how important is it that they get semantically similar answers?" [R1]. For a policy FAQ, the answer is very important. For a creative feature, perhaps not.
Everyday example. A golden dataset is like the common test paper of a school year: each question has a marking scheme (the oracle), says which page of the textbook it comes from (the source), and is marked as core or not (the risk). The paper is reused every term, so the classes' marks can be compared with each other.
Good vs bad.
| Weak case | Good case | |
|---|---|---|
| Expectation | "expected": "Bạn được đổi trả trong 30 ngày kể từ ngày nhận hàng.", copied from the model's output |
"oracle": {"facts": [["30 ngày"], ["kể từ ngày nhận hàng", "từ khi nhận hàng"]], "lang": "vi"} |
| Source, risk | None | "source": "policy §1", "risk": "high" |
| Why | A correct answer worded differently fails; nobody can check where the expectation came from | Every correct wording passes; a reviewer opens §1 to check the expectation itself |
4.2 A dataset has defects too
| Dataset defect | Sign | Example |
|---|---|---|
| Oracle too loose | A wrong answer still passes | Q-COD accepts "khi nhận hàng" (on delivery) or "COD": an answer that only contains "COD" but states the condition wrongly still passes |
| Oracle too strict | A correct answer fails | Accepting only "3-5 ngày" while "3 đến 5 ngày" (the same range with the word for "to" instead of a dash) is also correct |
| Expectation contradicts the source | Fails consistently in every version | A case expects a figure that differs from the policy |
| Missing case | A requirement has no case | No question about cancelling an order |
The strongest sign of a "wrong expectation" is a case that fails in every run, in every version. Before you
report a product defect, open the source (source) and compare.
Everyday example. The marking scheme has the wrong final figure for question 5: the whole class gets that question "wrong", including the best student. When every paper fails the same question, the teacher checks the marking scheme before taking marks off the whole class.
Worked example: an oracle that is too strict. Grade three answers with the oracle of Q-SHIP (policy §2: 3-5
working days). Save the following as try_l03.py in the lab folder, run python try_l03.py, then delete the file:
from lab import dataset, oracles
ship = next(c for c in dataset.load() if c["id"] == "Q-SHIP")
for answer in ("Đơn hàng thường được giao trong 3-5 ngày làm việc.",
"Đơn hàng được giao trong 3 đến 5 ngày làm việc.",
"Đơn hàng được giao trong 1-2 ngày làm việc."):
print(oracles.check(answer, ship["oracle"]) or "pass", "<-", answer)
Output (copied from a real run on Python 3.14.6 and 3.12.3, Linux, 2026-11-06; both versions gave identical output):
pass <- Đơn hàng thường được giao trong 3-5 ngày làm việc.
["missing fact ['3-5 ngày']"] <- Đơn hàng được giao trong 3 đến 5 ngày làm việc.
["missing fact ['3-5 ngày']", "forbidden '1-2 ngày'"] <- Đơn hàng được giao trong 1-2 ngày làm việc.
- Answer 1 is right and passes.
- Answer 2 is right as well according to §2 ("3 đến 5 ngày", the same range written with a word), but it fails because the oracle
accepts only the exact string
3-5 ngày: the oracle is too strict. - Answer 3 is wrong and is stopped twice: a missing fact, and a forbidden phrase.
The current model never says answer 2, so this defect has not shown yet. A new model that says "3 đến 5 ngày" will look like a regression although its answer is right. Try an oracle with a right and a wrong answer before it goes into the dataset (L1-M04-L01).
4.3 The baseline
A baseline is the recorded result of the dataset under one configuration. A usable baseline must record:
- the configuration: prompt version, model ID (L01), mode;
- the number of runs and the seed (in the simulation) or the time of the run (with a real API);
- the fingerprint of the dataset: a hash of the cases and oracles;
- the passes, fails and errors of each case, and a few failure samples.
The fingerprint solves a very common mistake: someone loosens an oracle, the pass rate rises, and the report calls it an "improvement". If the dataset changes, the fingerprint changes, and the comparison is refused.
Everyday example. A fingerprint is like the code of an exam paper (paper 101, paper 102): two classes can compare marks only when they sat the same paper code. Changing even one question makes a new paper code.
Worked example. What changes a fingerprint? Save the following as try_l03.py in the lab folder, run
python try_l03.py, then delete the file:
from lab import baseline, dataset
cases = dataset.load()
print("original: ", baseline.fingerprint(cases))
print("tags changed: ", baseline.fingerprint([dict(c, tags=["x"]) for c in cases]))
print("question reworded:", baseline.fingerprint([dict(cases[0], question="Đổi trả được không?"), *cases[1:]]))
print("one case removed: ", baseline.fingerprint(cases[:-1]))
Output (copied from a real run on Python 3.14.6 and 3.12.3, Linux, 2026-11-06; both versions gave identical output):
original: 14026646ef678dee
tags changed: 14026646ef678dee
question reworded: fea9aca5ccbb7001
one case removed: 103d07d301e5379e
- Changing
tags(used only to filter reports): the fingerprint stays the same, because tags do not change the grading. - Changing the question of one case: the fingerprint changes, because the model receives a different question.
- Removing a case: the fingerprint changes, because the overall rate is now computed over a different set of questions.
In both of the last two situations, check_comparable refuses to compare against the old baseline.
4.4 When to rebuild a baseline
- The dataset changes (a case added, an oracle changed, a wrong expectation fixed): the old baseline can no longer be compared.
- A behaviour change has been accepted (for example, a new version is released): the new baseline becomes the point of comparison for next time.
- Do not rebuild a baseline just to make a regression "disappear".
Everyday example. If a school changes the exam paper mid-term, marks can no longer be compared with the old paper. But nobody changes the paper just because a class did badly.
Good vs bad.
| Situation | Weak practice | Good practice |
|---|---|---|
| A new version drops Q-SHIP from 98% to 40% (L04) | Rebuild the baseline on the new version so the report is "green" | Keep the old baseline and report the regression; rebuild only when a version has been accepted for release |
| An oracle that was too strict has just been fixed | Keep comparing the candidate with the old baseline | Record why it was fixed, rebuild the baseline and rerun the candidate on the new dataset (new fingerprint) |
5. Technical deep dive
5.1 lab/dataset.py
load(path) reads JSONL (one case per line) and fails closed: a missing field, a duplicate id, an unknown
risk, an oracle with an unknown key, or an empty oracle, or a file without any case all raise an error.
5.2 lab/baseline.py
fingerprint(cases): the SHA-256 of theid,questionandoracleof each case, taking the first 16 characters. Changingtagsdoes not change the fingerprint; changing a question or an oracle does.build(model, cases, n, seed, label): runs the whole dataset and returns a dict that can be saved as JSON.check_comparable(a, b): raises an error if the fingerprints or the sets of cases differ.
5.3 The Python you need for this lesson
- JSONL: each line is a separate JSON document. Read it with
for line in text.splitlines(): json.loads(line). hashlib.sha256(bytes).hexdigest()creates a hash (seen in L1-M03-L05).
6. The QA perspective
- What to review in a dataset: every requirement has at least one case; every case has a source; every oracle has been tried with one correct answer and one wrong answer (L1-M04-L01).
- What can go wrong: expectations copied from the model's output instead of from the source; a baseline that does not record the configuration; comparing two runs on two different datasets; rebuilding the baseline to hide a regression.
- Reporting: the dataset version (the fingerprint) goes with every result.
7. Real-world scenarios
Scenario 1 (fictional): expectations copied from the model. A team creates a golden dataset by running the
model and saving its answers as the expectations. A wrong answer about the warranty period is saved as well. Every
later version "passes" that question, and the defect survives for six months. Lesson: expectations must come from
the source (source), not from the model.
Scenario 2 (fictional): an "improvement" from editing oracles. The pass rate rises from 82% to 91% after a sprint. On inspection, half of the increase comes from loosening three oracles in the same commit. The fingerprint of the dataset had changed, but the report did not record it.
8. Hands-on tutorial
8.1 Running the demo
python -m lab.demo l03
Output (copied from a real run, 2026-10-31):
config: faq-v1@sim-2026-09/sample | runs/case: 50 | seed: 1 | dataset: 14026646ef678dee
Q-REFUND passes=50 fails= 0 errors=0
Q-SHIP passes=49 fails= 1 errors=0
Q-COD passes=48 fails= 2 errors=0
Q-ADDR passes=50 fails= 0 errors=0
Q-WARRANTY passes=50 fails= 0 errors=0
Q-HOTLINE passes=40 fails=10 errors=0
Q-CANCEL passes=34 fails=16 errors=0
Q-FREE-RETURN passes=42 fails= 8 errors=0
fingerprint after loosening one oracle: d1fcd94a9f1f586c
Reading the output:
- The first line is the baseline's configuration: without that line, the figures below cannot be compared with anything.
- Q-HOTLINE (40/50) and Q-CANCEL (34/50) are already unstable in the baseline itself. In L04 and L05, do not mistake this for a regression.
- The last line: loosening one oracle changes the fingerprint.
8.2 Running the tests
python -m pytest tests/test_l03_baseline.py -v
8.3 Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
ValueError: ... fingerprints differ |
The two runs use different datasets | Rebuild the baseline on the current dataset |
ValueError: line N: ... |
A case lacks a field or has a wrong value | Read the message; it names the line and the field |
json.decoder.JSONDecodeError |
A JSONL line is broken across two lines | Each case must sit on exactly one line |
9. Independent exercise
Problem: Two oracles in the dataset are too loose.
Requirements:
- In
exercises/my_golden.jsonl(a copy of the dataset), tighten the oracles of two cases. Hint: Q-COD accepts either of two phrases. - Run
python -m pytest exercises/test_l03_my_golden.py. The test checks that the fingerprint has changed and that the new oracles do not fail the correct answers offaq-v1. - For each oracle you changed, write a wrong answer that the old oracle lets through and the new oracle blocks.
Deliverable: the edited JSONL file and the two wrong answers with an explanation.
Acceptance criteria: the test passes; each new oracle is still based on the source (data/policy.md), not on
the model's wording.
Further hint: Q-ADDR does not check that the answer is about changing the address. Every new constraint
must be in data/policy.md; a constraint without a source (for example, the length) is a product decision and must
be asked about first.
Hint: facts is a list of groups; each group needs at least one of its phrases to be present. Two separate
groups mean that both are needed.
9.1 Extra exercise: review a dataset without running the model
Time: 15-30 minutes. File: exercises/test_l03_extra_dataset_audit.py.
Problem: Two of the defects in §4.2 can be found just by reading the dataset and the policy: a missing case (a policy section that no case cites) and an expectation that is not in its source (a case requires a phrase that the section it cites does not contain).
Requirements:
- Run
python -m pytest exercises/test_l03_extra_dataset_audit.py. Untouched, 3 tests fail with a message starting withFailed: TODO. - Write
uncovered_sections(cases, sections): the sections (in policy order) that no case cites. - Write
facts_not_in_source(cases, sections): everyfactsgroup of which no phrase appears in the very section that the case cites. - Run again until you get
3 passed. Write one sentence: why is the caseM-WRONGin the test, although "30 ngày" is in the policy?
Acceptance criteria: 3 tests pass; the answer to step 4 says that you must compare with the cited section, not with the whole policy.
Hint: cited(case) and policy_sections(text) are given. Mind §1 and §10: compare with ==, not with in.
9.2 Real-world scenario: a mobile operator's data-plan FAQ (fictional)
The mobile operator "Sóng Xanh" (fictional) has a chatbot that answers questions about its plans. Policy excerpt (in English here; the dataset below quotes the Vietnamese original):
- §1 DATA70 plan: 70.000 đồng per month, 5 GB per day.
- §2 Daily allowance used up: the speed drops, no extra charge.
- §3 Cancelling the plan: text HUY DATA70 to 999, free of charge.
- §4 International roaming: DATA70 does not apply abroad.
- §5 Renewal: automatic every 30 days.
A colleague sends a draft golden dataset:
{"id": "D1", "question": "Gói DATA70 giá bao nhiêu?", "oracle": {"facts": [["70.000"]], "lang": "vi"}, "source": "policy §1", "risk": "medium"}
{"id": "D2", "question": "Hết dung lượng ngày thì sao?", "oracle": {"facts": [["tính thêm phí"]], "lang": "vi"}, "source": "policy §2", "risk": "high"}
{"id": "D3", "question": "Hủy gói thế nào?", "oracle": {"facts": [["HUY DATA70"], ["999"]], "lang": "vi"}, "source": "policy §3", "risk": "low"}
{"id": "D4", "question": "Ra nước ngoài có dùng DATA70 được không?", "oracle": {"facts": [["được", "không"]], "lang": "vi"}, "source": "policy §4", "risk": "high"}
{"id": "D5", "question": "Mỗi ngày được bao nhiêu GB?", "oracle": {"facts": [["5 GB"]], "lang": "vi"}, "risk": "medium"}
The team already has a baseline from last month, built on an older draft of this dataset.
Your task (45-60 minutes):
- Review each case: check it against the policy section it cites, and name every problem with one of the defect
types of §4.2 (or a defect that
dataset.loadwould reject, §5.1). - Rewrite the cases that have problems (oracle, source, risk). Every new oracle must be based on the wording of the policy.
- Add cases for every requirement that is missing.
- Write 2-3 sentences: can last month's baseline still be used for comparison, and what must the team do next?
A good answer has:
- Each case checked against the section it cites, and each problem named with a defect type of §4.2 or §5.1
- Each rewritten oracle based on the policy's wording, and tried with a right and a wrong answer
- After the fixes, every policy section has at least one case
- Risk levels with a reason: what the customer loses if the chatbot answers that question wrongly
- A conclusion about the old baseline based on the fingerprint, with the next steps
10. Knowledge check
0/19 done · Results are kept in this browser only.
P02 · True or false
P03 · Short answer
Name four pieces of information that a baseline must record.
P04 · Short answer
Why should you not create expectations by saving the model's answers?
P05 · Short answer
(Scenario) The pass rate rises by 9% after a sprint, and in the same sprint three oracles were changed. What do you check before reporting an "improvement"?
P06 · Match
P08 · Multiple choice
P09 · Spot the bug
The fingerprint() function below is copied from lab/baseline.py, with one line modified. Find the bug.
def fingerprint(cases):
canonical = json.dumps([{k: c[k] for k in ("id", "question")} for c in cases], sort_keys=True,
ensure_ascii=False)
return hashlib.sha256(canonical.encode("utf-8")).hexdigest()[:16]P10 · Recall
Lesson: L1-M06-L02P11 · Select all that apply
P12 · True or false
P13 · Short answer
While comparing two runs, you get ValueError: ... fingerprints differ. What does this error tell you, and what do you do?
P15 · Multiple choice
P16 · True or false
P17 · Apply now
In code-labs/l1-m06, do the extra exercise of §9.1 in exercises/test_l03_extra_dataset_audit.py, then run python -m pytest exercises/test_l03_extra_dataset_audit.py.
P18 · Match
P19 · True or false
11. Summary
- Concepts: a golden dataset with property-based oracles, sources and risks; dataset defects; a baseline with its configuration and fingerprint; when to rebuild a baseline.
- Skills: writing and reviewing cases; building and saving a baseline; refusing to compare across datasets.
- Pitfalls: expectations copied from the model; oracles that were never tried; comparing across datasets; rebuilding the baseline to hide a defect.
- You can now: maintain a golden dataset and a baseline that are usable for regression testing.
12. References
| ID | Title | Publisher | URL | Accessed | Relevance |
|---|---|---|---|---|---|
| R1 | Define success criteria and build evaluations | Anthropic | https://platform.claude.com/docs/en/test-and-evaluate/develop-tests | 2026-10-31 | Consistency criteria; grading methods (code, human, LLM) |
Key terms (English ↔ Vietnamese)
| English | Tiếng Việt |
|---|---|
| Golden dataset | Bộ dữ liệu chuẩn dùng lại cho mọi lần test |
| Baseline | Kết quả gốc để so sánh |
| Fingerprint (hash) | Dấu vân tay (mã băm) |
| JSONL | JSON Lines, mỗi dòng một JSON |
| Source of truth | Nguồn sự thật cho kỳ vọng |