Module: L2-M01 · Duration: ~90 min (estimate, including the independent exercise) · Previous: L1-M08-L04 · Next: L02
1. Introduction
In Level 1 you wrote a lot of tests: checking a schema, checking that an answer contains a fact, running a case repeatedly and measuring the pass rate (L1-M06). Level 2 changes the question. Instead of "is this code correct?", we ask "how good is this AI feature, and how sure are we?". The second question is the job of evaluation (often shortened to eval).
This lesson lays the foundation: tests and evaluations look alike in that both use an input, an output and a check, but they prove different things. Confusing the two leads to two common professional mistakes: reporting "testing is done, everything passes" for a system that is still wrong about one time in ten, or the opposite, dropping unit tests because "with AI you have to use evals".
This is the first competency of Level 2, and every later lesson in the module (quality criteria, grader types, statistics, strategy) builds on it.
2. Learning objectives
- Distinguish a test from an evaluation by what is checked, the kind of conclusion and the form of the result.
- Explain why a passing test does not prove the system is correct, while a failing test proves there is a defect (provided the test and the oracle are correct).
- Classify a requirement as a test, an eval, or both, using three questions.
- Run the same system two ways (one test, one evaluation) and read the two different results.
- Record the configuration of an evaluation run so that results can be compared later.
3. Prerequisites and tools
- L1-M08-L04: you already have a test suite running in CI for an LLM feature.
- L1-M06-L02: pass rates and the Wilson interval. This lesson reuses them and does not reteach them.
- L1-M04-L01: property-based oracles (checking properties of an answer instead of comparing strings).
- The code lab
code-labs/l2-m01, installed per its README. You only need pytest, no API key, no cost.
4. Concepts
4.1 Test: check your code against a fixed input
A test runs a piece of code with a fixed input and compares the output with a fixed expectation. The result is pass or fail. If the code and the environment do not change, rerunning gives the same result.
For an AI feature, most of your code is still ordinary code: the function that reads the dataset file, the grading function, the function that computes the confidence interval, the function that writes the configuration. These functions have a well-defined correct answer, so they need unit tests like any other code.
4.2 Evaluation: measure the quality of the model's output on a set of cases
An evaluation runs the AI system on many cases, scores each output with a grader, and then aggregates the scores into a metric, usually a rate. Anthropic describes an eval as "give an AI an input, then apply grading logic to its output to measure success"; a task is "a single test with defined inputs and success criteria"; each attempt at a task is a trial, because output varies between runs; and a grader is "logic that scores some aspect of the agent's performance" [R1]. The lab in this module uses exactly those three concepts: case, run and check.
OpenAI's evaluation guide gives the reason evals are needed: "Models sometimes produce different output from the same input", so traditional software testing methods are "insufficient for AI architectures" [R2]. The guide does not say tests are useless; it says tests alone are not enough.
4.3 What a passing test proves, what a failing test proves
There is an asymmetry that QA needs to hold firmly:
- A failing test is strong evidence: we have a specific input on which the system gets it wrong, and one wrong example is enough to prove a defect exists, provided the test and the oracle are correct. A failing test can come from a wrong oracle or from the environment (you classified ORACLE_DEFECT and ENVIRONMENT in L1-M06-L05), so a failure needs triage before it is called a defect.
- A passing test is weak evidence: the system is correct on that input, in that run. It says nothing about other inputs or other runs.
With a non-deterministic system, this asymmetry is heavier. Suppose 10% of runs are faulty. The lab computes the probability that a suite of n tests, each run once, sees at least one fault: n=1 is 0.100; n=5 is 0.410; n=20 is 0.878; n=40 is 0.985 (§8). That means a "green" suite of 5 tests happens 59% of the time even when the system is 10% faulty. "Green tests" is not yet "a good system".
4.4 What an evaluation proves (and what it does not)
The result of an evaluation is an estimate: "on these 40 cases, with 10 runs per case, 359/400 runs passed (0.897)". An estimate carries uncertainty, so we attach a confidence interval (lesson L04). It is only valid for the input distribution the dataset represents: a dataset with only grade 3 problems says nothing about grade 5.
NIST (the US National Institute of Standards and Technology) gives a recommendation in the same direction for generative AI: avoid "extrapolating GAI system performance or capabilities from narrow, non-systematic, and anecdotal assessments" [R3]. A few manual tries are an anecdotal assessment; evaluation replaces it with a systematic measurement.
4.5 One requirement, two ways to check it
Take the fictional product HocVui Tutor (a chatbot that helps grade 3-5 students with math, used throughout the module). The following table classifies seven requirements. The "Why" column is the important part, because it is the argument you will use to defend your classification.
| Requirement | Type | Why |
|---|---|---|
The function that reads cases.jsonl rejects a line missing id |
test | Our own code, with a well-defined correct answer |
The no_echo grader returns None when the reply does not contain a phone number |
test | A pure function, fixed input |
| The tutor never states the answer to an exercise | eval | Model behavior; "never" can only be measured as a rate |
| At least 98% of replies are in Vietnamese | eval | A rate over an input distribution |
| Replies are friendly and encouraging | eval (human/model) | No well-defined answer; needs a person or a judge |
run_eval writes the dataset fingerprint into the configuration |
test | Our own code |
| v2 is no worse than v1 on correctness | eval | Compares two rates |
Three common misconceptions
- "Eval is a bigger test." No. A test answers "is this defect present?" with pass/fail; an eval answers "what is the rate?" with a number and its uncertainty.
- "Eval replaces tests." No. A bug in the grading code silently makes every number wrong. While writing the lab, the
no_leakgrader initially missed every sentence with a period right after the answer ("Đáp số là 6.") because the regex was too strict; we only noticed when a different count gave 0/140. A unit test with a fixed input catches that bug in a second. - "100% pass means correct." It only means no defect was seen in the sample that was run (§4.3, and L04 will quantify it).
5. Technical deep dive
5.1 The three concepts in the lab
| Concept [R1] | In the lab | Code |
|---|---|---|
| Task | A case: a student's question, an expectation, the source of the expectation | data/cases.jsonl, lab/dataset.py |
| Trial | A run: one call to the tutor with a seed and a run index |
SimulatedTutor.reply(case_id, seed, run) |
| Grader | A check: a function that returns None if it passes, or a reason if it fails |
lab/graders.py |
The tutor in the lab is a seeded simulation with known defects (see lab/tutor.py). The same (version, case, seed, run) always
gives the same reply. That is a property of the simulation so the lesson is reproducible. A real API is not like that, and the real error rate
is never known in advance.
5.2 A run must carry its configuration
runner.run_eval(system, cases, runs, seed) returns the result rows and a configuration record: the system, the seed, the number of runs,
the number of cases, and the fingerprint (a short hash) of the dataset. Two results are comparable only when the configurations are compatible. NIST
also asks for this to be recorded: "Test sets, metrics, and details about the tools used during TEVV are documented", where TEVV
means test, evaluation, verification, validation (MEASURE 2.1) [R4]. A number without a configuration is a number that cannot be verified.
Everything in the lab falls into two groups: the deterministic parts (loader, graders, statistics, configuration recording), covered by 74 tests in tests/; and the tutor, which is measured by evaluation.
6. The QA perspective
6.1 Three questions to classify a requirement
- Subject: is this my code, or the model's behavior? (code → test)
- Answer: is there a single correct answer for a fixed input? (yes → test)
- Form of conclusion: do I need "is there a defect or not" or "what rate, and how sure"? (rate → eval)
If a requirement falls into both groups, split it. For example "the tutor answers in Vietnamese" consists of a test (the vi function recognizes
accented letters correctly) and an eval (the rate of Vietnamese replies).
6.2 Reporting results correctly
- Write "359/400 runs passed (0.897), Wilson interval 0.864-0.924, seed 1, dataset
47065d9256b4", not "it passed". - State the sample clearly: 40 cases x 10 runs is not 400 independent cases (L04). When all you have is green tests, say "no defect was found in the inputs tried", not "there are no defects".
7. Real-world scenarios
Scenario 1 (fictional): "three green tests". The HocVui Tutor team has three tests for case H01, each run once with a different seed, and all three pass. They release. Two weeks later parents report that the tutor "just gives the answer" on other exercises. An evaluation of 40 cases x 10 runs shows 359/400 passing; the "exercise" group of cases passes only 120/140 and has 12 replies that state the answer. The three green tests were not wrong; they just proved too little.
Scenario 2 (fictional): "evals are enough". Another team drops the grader's unit tests. A regex change makes the no_leak grader miss answers followed by a period, the "pass" rate goes up and the team thinks the tutor got better. An eval cannot detect a bug in the grader on its own; the grader's tests can.
8. Hands-on tutorial
8.1 Setup
cd academy-content/code-labs/l2-m01
python3 -m venv .venv && source .venv/bin/activate # Windows: .venv\Scripts\activate
python -m pip install -r requirements.txt
python -m pytest # 74 passed
8.2 Run the demo
python -m lab.demo l01
Output (copied from a real run on Python 3.14.6 and 3.12.14, 2026-11-03; the two versions gave identical output):
A. one test, one run, three different seeds (case H01)
seed 1: PASS Hãy gạch chân các số trong đề, rồi nghĩ xem phép chia hợp lý ở đâu. Em chưa chịu đọc kỹ rồi.
seed 2: PASS Gợi ý: đây là bài về phép chia. Bạn bắt đầu từ bước nào?
seed 3: PASS Hãy gạch chân các số trong đề, rồi nghĩ xem phép chia hợp lý ở đâu. Dễ vậy mà cũng hỏi.
B. the same system as an evaluation: 40 cases, 10 runs each, seed 1
pass 359/400 = 0.897, 95% Wilson interval 0.864-0.924
first failure: H02 run 9: max_words:60 -> 83 words > 60
C. chance that a suite of n single-run tests sees at least one failure when 10% of runs fail
n= 1: 0.100
n= 5: 0.410
n=20: 0.878
n=40: 0.985
D. two versions, same dataset and seed, 10 runs per case
tutor-v1: 359/400 = 0.897 (0.864-0.924)
tutor-v2: 333/400 = 0.833 (0.793-0.866)
Reading the output:
- A. Three tests pass, even though two of the replies have an extra curt sentence ("Em chưa chịu đọc kỹ rồi"): the code check does not see tone (L02-L03).
- B. The same system, but the evaluation shows 41 failures out of 400. The "first failure" line is existence proof: one specific reply (H02, run 9) is 83 words long, exceeding the 60-word limit.
- C. The probability that a suite of tests sees a fault grows with n, but never becomes certain.
- D. Two versions on the same dataset and seed: 0.897 versus 0.833. The two intervals almost separate but still overlap slightly (v2's upper bound is 0.866, v1's lower bound is 0.864); L04 asks when a difference like this can be trusted.
8.3 Write two checks of your own
Save this file as try_l01.py inside the lab folder (so that import lab works):
from lab import dataset, graders, runner
from lab.tutor import SimulatedTutor
cases = dataset.load()
h01 = next(c for c in cases if c["id"] == "H01")
tutor = SimulatedTutor("v1")
# A test: one case, one run, a fixed expectation.
reply = tutor.reply("H01", seed=1, run=0).text
print("test :", "PASS" if not graders.grade(reply, h01) else "FAIL")
# An evaluation: many cases, many runs, a rate.
run = runner.run_eval(tutor, cases, runs=10, seed=1)
print("eval :", f"{run.passes()}/{run.n()} cases-runs passed")
print("config :", run.config)
Run python try_l01.py. Output:
test : PASS
eval : 359/400 cases-runs passed
config : {'system': 'tutor-v1', 'seed': 1, 'runs': 10, 'cases': 40, 'dataset': '47065d9256b4'}
The config line is what lets you say "where this result came from". Change one character in one case and dataset changes: try it and see.
8.4 Run the lesson's tests
python -m pytest tests/test_l01_testing_vs_eval.py -v
Result: 11 passed. Read test_a_single_test_can_pass_on_three_seeds_while_the_system_is_defective: it asserts that three seeds pass and the evaluation still has failing rows.
8.5 Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
ModuleNotFoundError: No module named 'lab' |
The script was run outside the lab folder | Put try_l01.py in code-labs/l2-m01 and run it from there |
| Results differ from the lesson | Different seed or number of runs | Use seed=1, runs=10 |
9. Independent exercise
Problem: Classify seven requirements as test or eval and compute the minimum size of a test suite.
Requirements: complete exercises/test_l01_requirements.py:
- TODO 1: assign
"test"or"eval"to R1-R7 inCLASSIFICATION(the seven requirements are in the file's docstring). - TODO 2: find the smallest number of single-run tests such that the probability of seeing at least one fault reaches ≥ 0.95 when 10% of runs are faulty. Use
lab.stats.detect_probability, do not guess. - For each requirement you classify as
eval, write one sentence in a comment: which conclusion a test cannot give.
Test data: the seven requirements in the docstring; the function detect_probability(n, failure_rate).
Deliverable: the completed test file and four explanatory sentences (one for each eval requirement).
Acceptance criteria: python -m pytest exercises/test_l01_requirements.py passes (2 tests); each eval choice has a one-sentence reason.
Hint: range(1, 200) and next(...); remember the answer must be the smallest number that reaches the threshold, so the test checks both n and n - 1.
10. Knowledge check
0/18 done · Results are kept in this browser only.
P02 · True or false
P03 · Short answer
In the l01 demo, case H01 passes on all three seeds, yet the evaluation of 40 cases x 10 runs gives 359/400. Why do three green tests not contradict 41 failures?
P04 · Select all that apply
P05 · Fill in the blank
P07 · Match
P08 · Spot the bug
The snippet below is taken from §8.3 with one spot changed. It prints test : FAIL for a correct reply on case H01. Find the bug.
reply = tutor.reply("H01", seed=1, run=0).text
print("test :", "PASS" if graders.grade(reply, h01) else "FAIL")P09 · Short answer
Write the correct report line for the result of tutor v1 (359/400) and say why "it passed" is not enough.
P10 · Essay
The requirement "the tutor answers in Vietnamese" contains both a test and an eval. Write 5-8 sentences: split the requirement into two parts, say what each part checks, and what form of result each gives.
P11 · Multiple choice
P12 · True or false
P13 · Select all that apply
P14 · Recall
Lesson: L1-M06-L02P15 · Recall
Lesson: L1-M04-L01P17 · True or false
P18 · Fill in the blank
11. Summary
- Concepts: a test checks code against a fixed input and gives pass/fail; an evaluation measures output quality on a set of cases and gives a rate with uncertainty; a failing test is strong evidence, a passing test is weak evidence; case, run, check are the lab's three concepts.
- Skills: classify requirements with three questions; run the same system two ways; record the configuration and the dataset fingerprint.
- Traps: treating a few green tests as "a good system"; treating eval as a replacement for the grader's unit tests; reporting a number without its configuration.
- You can now: look at a requirement for an AI feature and say whether it needs a test, an eval or both, and why.
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 | Definitions of eval, task, trial, grader |
| R2 | Evaluation best practices | OpenAI | https://developers.openai.com/api/docs/guides/evaluation-best-practices | 2026-11-03 | Different outputs from the same input; traditional testing is not enough (page redirected from platform.openai.com) |
| R3 | NIST AI 600-1: Artificial Intelligence Risk Management Framework: Generative Artificial Intelligence Profile (July 2024) | NIST | https://nvlpubs.nist.gov/nistpubs/ai/NIST.AI.600-1.pdf | 2026-11-03 | MS-2.5-001: avoid extrapolating from narrow, anecdotal assessments |
| R4 | NIST AI 100-1: Artificial Intelligence Risk Management Framework (AI RMF 1.0) (January 2023) | NIST | https://nvlpubs.nist.gov/nistpubs/ai/NIST.AI.100-1.pdf | 2026-11-03 | TEVV; MEASURE 2.1: record the test set, metrics, tools |
Key terms (English ↔ Vietnamese)
| English | Tiếng Việt |
|---|---|
| Test | Kiểm thử: input cố định, kỳ vọng cố định, pass/fail |
| Evaluation (eval) | Đánh giá: đo chất lượng trên một tập case, cho một tỷ lệ |
| Grader | Bộ chấm điểm |
| Task / trial | Một case / một lần chạy case đó |
| Metric | Số đo |
| TEVV | Test, evaluation, verification, validation |
| Dataset fingerprint | Dấu vân tay dataset (hash ngắn) |