From instructions to verifiable acceptance criteria

Study time
≈ 2.5 h (estimate)
Needs
L1-M02-L01
Updated
2026-11-06

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: L1-M02 · Duration: ~150 min (estimate, including the independent exercise) · Previous: L01 · Next: L03 - Designing a prompt test matrix: partition, boundary and pairwise

1. Introduction

A prompt is a specification written in natural language. Each instruction sentence in a prompt is a requirement that the product team expects the model to follow. But sentences such as "explain at a level suited to the learner" or "answer briefly" do not automatically become tests.

The tester's job here is a familiar one from traditional testing: break the specification into atomic requirements (each requirement says only one thing), write acceptance criteria for each requirement, choose an oracle, and keep traceability between requirements and test cases.

2. Learning objectives

  1. Decompose a list of instructions into atomic requirements.
  2. Rewrite a vague requirement as a verifiable criterion, or determine that it needs human review.
  3. Choose a suitable oracle (deterministic, reference answer, heuristic, human review) for each requirement and explain the choice.
  4. Run a test suite with traceability and read the per-requirement coverage report.
  5. Detect a requirement that no test covers yet.

3. Prerequisites and tools

  • L01 and the code-labs/l1-m02 lab.
  • L1-M01-L05: the types of oracle.
  • The idea of a requirement traceability matrix from traditional testing. If you have not met it: it is a table that links each requirement to the test cases that check it.

4. Concepts

4.1 One instruction, several requirements

This sentence in the LinguaBot prompt:

"Write the explanation in Vietnamese, in at most two sentences, suitable for the learner's level."

contains three different requirements, and each requirement needs a different oracle:

ID Atomic requirement Verifiable by Oracle
R3 The explanation is in Vietnamese It has Vietnamese diacritics Heuristic (limited, see L1-M01-L05)
R4 At most two sentences Count sentences by ., !, ? Deterministic
R5 Suited to the learner's level A reviewer scores it against criteria Human review

If you write only one test for the whole sentence, that test either misses R5, or pretends to check R5 with a rule that is not good enough.

Everyday example. A customer books a delivery and writes "fast, on time, careful". Those are three requirements with three ways of checking: "fast" is measured in minutes, "on time" is compared with the agreed time slot, "careful" means looking at whether the parcel is dented. If the courier arrives on time but breaks the item, nobody can mark the whole sentence "pass" or "fail".

Worked example. One reply, three requirements, three different verdicts. Save the snippet below as try_l02.py in the lab folder, run python try_l02.py, then delete the file:

from lab.checks import run_checks

reply = ('{"corrected": "She goes to school every day.", '
         '"explanation": "The verb must agree with the subject. Use goes. Remember it!"}')
checks = {"corrected_equals": "She goes to school every day.",   # R2
          "explanation_in_vietnamese": True,                     # R3
          "max_sentences": 2}                                    # R4
for name, arg in checks.items():
    print(f"{name:<26} {run_checks(reply, {name: arg}) or 'pass'}")

Output (copied from a real run on Python 3.14.6 and 3.12.3, Linux, 2026-11-06; both versions print the same):

corrected_equals           pass
explanation_in_vietnamese  ['explanation does not look Vietnamese']
max_sentences              ['explanation has 3 sentences, limit 2']

Step by step: the correction is right, so R2 passes. The explanation is written in English, so R3 fails. It has three sentences (., ., !), so R4 fails. And no check here can answer R5. If the whole instruction had only one "good reply" test, you would only know that it failed, not which requirement it failed on.

4.2 From vague to verifiable

Vague Verifiable Note
"Answer briefly" "The explanation has at most 2 sentences" The number must be confirmed by the product owner
"Keep the meaning" "The corrected sentence keeps the tense and subject of the original; for sentence set X, the correction equals the reference answer" Reference answers for known sentences
"Friendly" Cannot be turned into rules entirely Human review with a rubric (Level 2). A secondary rule can be added: contains no word from a banned list
"Do not answer off-topic" "For a request that is not about grammar, corrected is null and the explanation states that the bot only helps with grammar" Lesson L04 will show why the second half of this sentence matters

Rule: if you cannot write an input and a way to decide pass/fail for a requirement, the requirement is not yet verifiable. Take it back to the product owner, with a specific question.

Good vs bad. Two ways to write acceptance criteria for the same wish:

Weak criterion Good criterion
Text "The bot corrects sentences properly and explains briefly." "For the input She go to school every day, corrected equals She goes to school every day.; explanation has at most 2 sentences, counted by ., !, ?."
Has an input No Yes
How pass/fail is decided By the feeling of whoever runs it String comparison; sentence count
Who set the number There is no number "2 sentences", confirmed by the product owner

4.3 Traceability

Traceability diagram: instruction in the prompt → atomic requirements (R1-R7) → test cases (TC-01...) → checks (oracle); requirements whose oracle is human_review go to the review queue.
Diagram: Traceability

In the lab, each test case has a requirements field that lists the requirements it checks. The coverage() function answers two questions:

  • Which automatable requirement is not covered by any test case yet?
  • Which requirement needs human review, and so needs a review process instead of an automated test?

A common misconception: "100% coverage means testing is complete." Per-requirement coverage only tells you that each requirement has at least one test. It does not tell you whether that test is strong enough. Lesson L04 will show a test that counts as "covering" a requirement but does not detect it when that requirement is violated.

Everyday example. A class register has a line for every pupil, including the ones who are absent, so an empty box shows at once. A sheet that lists only the pupils who turned up never shows who is missing. A traceability matrix, too, needs a line for every requirement, including one that has no test yet.

Good vs bad. Two ways to report the same run (§8.2):

Weak report Good report
"6/6 tests pass. Prompt v1 OK." "R1, R2, R3, R4, R6, R7 have automated tests, all passing (6 cases). R3 and R4 have only one case (TC-01). R5 (suitable for the level): not verified automatically, 0/10 samples reviewed."
The reader assumes every requirement has been verified The reader sees the thin spots (R3, R4) and the gap (R5)

5. Technical deep dive

5.1 Three data files

  • data/requirements.json: 7 requirements R1-R7. Each requirement has a source (the original sentence in the prompt), testable_as (how it is verified) and an oracle.
  • data/cases.json: 6 test cases TC-01 to TC-06. Each case has requirements, inputs (values for the template) and checks.
  • lab/checks.py: the check functions. The name of each check in the JSON corresponds to a function in CHECKS.

5.2 The check registry

CHECKS = {
    "is_json_object": check_is_json_object,
    "required_keys": check_required_keys,
    "corrected_equals": check_corrected_equals,
    ...
}

CHECKS is a dict: the key is the check name (a string), the value is the function. run_checks() reads the check names from the JSON, finds the matching function and calls it. If a check name is not in the registry (for example the typo corected_equals), the function raises an error instead of skipping it. This is the fail closed principle you met in L1-M01-L04: a mistyped check that silently passes is worse than no check at all.

5.3 Running the suite through the simulated model

run_suite(template, cases, model) renders the prompt for each case, calls model.complete(...), runs the checks, and returns the result of each case. The model is SimulatedTutor: a simulation that reacts to phrases in the prompt (see L01 section 5.3).

6. The QA perspective

  • What to test: each atomic requirement has at least one test case, or is explicitly placed in the human review queue.
  • Why: a requirement that is not separated out gets missed. A requirement with no clear oracle gets "tested" by gut feeling.
  • What can go wrong: one test case checks several requirements, and when it fails nobody knows which requirement was violated; a vague requirement is forced into a wrong rule; numbers (2 sentences, 3 seconds) are set by the tester without being confirmed.
  • Expected behaviour: each requirement has criteria agreed by the product owner.
  • How to detect it: a per-requirement coverage report, run with the test suite.
  • How to report it: by requirement, not just by the number of passing tests. For example: "R5: not verified automatically, 0/10 samples reviewed."

7. Real-world scenarios

Scenario 1 - LinguaBot (fictional; this is the lab). Seven requirements are split out of five instruction sentences. R5 ("suited to the level") cannot be automated at Level 1, so the report must state clearly that it has not been verified, instead of staying silent.

Scenario 2 - HR policy lookup assistant (fictional). The prompt says: "Answer using only the provided policy, cite the section number, and keep a professional tone." Split up: (a) use only the provided document, (b) include the section number, (c) a professional tone. (b) is deterministic (a regex for the section number). (a) needs a comparison with the document, at first by human review, later by faithfulness evaluation in Level 2. (c) is human review.

8. Hands-on tutorial

8.1 Reading the requirements and test cases

Open data/requirements.json and data/cases.json. For each requirement R1-R7, find the test cases that list it. For example, TC-01 checks R1, R2, R3, R4:

{"id": "TC-01", "requirements": ["R1", "R2", "R3", "R4"], "inputs": {"level": "A2", "learner_text": "She go to school every day"},
 "checks": {"required_keys": ["corrected", "explanation"], "corrected_equals": "She goes to school every day.", "explanation_in_vietnamese": true, "max_sentences": 2}}

Each check corresponds to one requirement: required_keys → R1, corrected_equals → R2, explanation_in_vietnamese → R3, max_sentences → R4.

8.2 Running the suite with prompt v1

python -m lab.runner

Actual output (2026-10-31):

coverage: {'uncovered': [], 'needs_human_review': ['R5']}

v1: 6/6 passed
  TC-01 PASS 
  TC-02 PASS 
  TC-03 PASS 
  TC-04 PASS 
  TC-05 PASS 
  TC-06 PASS 

Reading the result:

  • uncovered: []: every automatable requirement has at least one test case.
  • needs_human_review: ['R5']: R5 needs a separate review process. This is information that must appear in the report.
  • 6/6 pass on v1. In lessons L04 and L05 you will see that "6/6" does not mean the suite is strong enough.

8.3 Running the unit tests

python -m pytest tests/test_checks.py tests/test_runner.py -v

Expected result: 16 passed (9 + 7). A test worth noting:

def test_coverage_reports_a_requirement_with_no_case():
    without_injection_case = [c for c in CASES if c["id"] != "TC-05"]
    assert coverage(REQUIREMENTS, without_injection_case)["uncovered"] == ["R7"]


def test_unknown_check_name_fails_loudly():
    with pytest.raises(KeyError, match="unknown check"):
        run_checks(reply(corrected="x"), {"corected_equals": "x"})

The first test removes TC-05 and then asserts that coverage reports R7 as uncovered. This is how you test the coverage tool itself.

8.4 Troubleshooting

Symptom Cause Fix
KeyError: unknown check A check name is mistyped in the JSON Fix the name to match CHECKS
FileNotFoundError: data/cases.json The demo was run outside the lab folder cd code-labs/l1-m02
A new test case does not appear in coverage The requirements field was forgotten Add the list of requirement IDs

9. Independent exercise

Problem: The product team sends 6 new requirement sentences, and the suite has no case yet that checks R3 and R4 for a refusal answer (off-topic).

Requirements:

  1. Complete exercises/l02_requirements_worksheet.md: for each sentence S1-S6, decide whether it is verifiable, rewrite it if needed, choose an oracle, and write one test input.
  2. Add a test case TC-07 to data/cases.json: an off-topic request, checking R3 and R4, with a correct requirements field.
  3. Run python -m pytest and python -m lab.runner, then record the results. The shipped tests only check the original cases TC-01 to TC-06, so adding TC-07 does not turn them red.

Test data: the 6 sentences in the worksheet; an off-topic input of your choice (for example a question about the price of bitcoin).

Deliverable: the completed worksheet; data/cases.json with TC-07; the runner output.

Acceptance criteria: each sentence has an oracle and a reason; the sentences that cannot be verified automatically are tagged human_review or have a question for the product owner; TC-07 runs and has the correct requirements.

Hint: S4 ("under 3 seconds") is a performance requirement, not a prompt requirement. Ask: who measures it, and where?

9.1 Extra exercise: build the traceability matrix yourself

Time: 15-30 minutes. File: exercises/test_l02_extra_trace.py.

Problem: coverage() only answers "which requirement has no case?". In a review you need the whole table behind it: which cases verify each requirement. That table shows both the gap (R5) and the thin spots (R3 and R4 have only one case).

Requirements:

  1. Copy the file into tests/ and run python -m pytest tests/test_l02_extra_trace.py. Untouched, 4 tests fail with Failed: TODO: implement trace_matrix.
  2. Write the body of trace_matrix(requirements, cases): return a dict {requirement id: sorted list of case ids}, in the order of requirements. A requirement with no case still gets a line with an empty list. A case that names a requirement id that does not exist raises ValueError (fail closed, §5.2).
  3. Run again until you get 4 passed. Note the lines for R3 and R4, then write one sentence: why is "one case" a thin spot even though coverage reports nothing missing?

Acceptance criteria: 4 tests pass; R5 has the line []; a case with the id R9 makes the function raise an error instead of being skipped.

Hint: build the dict from requirements first ({r["id"]: [] for r in requirements}), and only then go through cases.

9.2 Real-world scenario: a refund support bot for an e-commerce marketplace (fictional)

The e-commerce marketplace "Cho Nhanh" (fictional) is about to launch a refund support bot. The instructions in its prompt:

- Answer in Vietnamese, politely and briefly.
- Only discuss refunds for orders placed in the last 30 days. For older orders, explain the policy and give the hotline number.
- Never promise a refund amount or a refund date.
- Always mention the order ID the customer gave.

Your task (45-60 minutes): write a requirements table like the one in §4.1 (id, atomic requirement, verifiable by, oracle, one test input), then a list of questions for the product owner.

A good answer has:

  • At least 8 atomic requirements, each line saying one thing
  • "Briefly" rewritten as a number waiting for the product owner's confirmation; "politely" marked human_review
  • Boundary values for "30 days" in the test inputs: an order 30 days old and one 31 days old
  • An oracle for "no promised amount/date" with its limits stated: a regex for amounts or dates can match wrongly (false fail) or miss (false pass), so human review is needed as well
  • Questions for the product owner, for example: do the 30 days count from the order date or the delivery date? What does the bot do when the customer gives no order ID?
  • Every requirement present in the table, including those with no automated test yet

10. Knowledge check

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

P02 · True or false

If coverage() returns uncovered: [], every requirement has been fully verified.

P03 · Short answer

Why does run_checks() raise an error on an unknown check name instead of skipping it?

P04 · Short answer

Rewrite "The bot must answer politely" as a criterion, and state which part needs human review.

P05 · Short answer

The product owner says: "Just get the tests passing, R5 isn't needed." How do you respond, and how do you report R5?

P06 · Match

According to §8.1, match each check of TC-01 to the requirement it checks.

P07 · Multiple choice

According to the table in §4.1, which type of oracle does R3 "The explanation is in Vietnamese" use?

P08 · Fill in the blank

According to §8.2, python -m lab.runner prints coverage: {'uncovered': [], 'needs_human_review': ['___']}. According to §8.3, python -m pytest tests/test_checks.py tests/test_runner.py -v gives ___ passed.

P09 · Spot the bug

The coverage function below is copied from lab/runner.py (with the oracle and ID checks left out) but has one defect. Find it.

def coverage(requirements, cases):
    covered = {r for case in cases for r in case["requirements"]}
    automated = [r["id"] for r in requirements]
    return {
        "uncovered": [r for r in automated if r not in covered],
        "needs_human_review": [r["id"] for r in requirements if r["oracle"] == "human_review"],
    }

P10 · Multiple choice

Scenario 2 in §7: "Answer using only the provided policy, cite the section number, and keep a professional tone." Which part can be verified with a deterministic rule?

P11 · Recall

Lesson: L1-M02-L01

Lesson L01: why does the template in the lab escape the user's input before filling it into <learner_text>?

P13 · Multiple choice

In the worked example in §4.1 (try_l02.py), which requirements does the sample reply fail?

P14 · True or false

With the six original cases, R3 and R4 each have exactly one case (TC-01), even though coverage() reports uncovered: [].

P15 · Select all that apply

What must a good traceability matrix (§4.3, §9.1) do?

P16 · Multiple choice

According to the "Good vs bad" table in §4.3, what does the good report say that "6/6 tests pass. Prompt v1 OK." does not?

P17 · Apply now

Do the extra exercise in §9.1: copy exercises/test_l02_extra_trace.py into tests/, run python -m pytest tests/test_l02_extra_trace.py once before editing it, write the body of trace_matrix, then run it again.

Checklist

11. Summary

  • Concepts: atomic requirements; verifiable criteria; an oracle for each requirement; traceability; per-requirement coverage is different from test strength.
  • Skills: split instructions; rewrite vague requirements; read a coverage report; test the measuring tool itself.
  • Traps: bundling several requirements into one test; forcing a semantic requirement into a wrong rule; staying silent about unverified requirements.
  • You can now: turn a prompt into a list of requirements with tests, and report the part that has not been verified.

12. References

ID Title Publisher URL Accessed Relevance
R1 Prompting best practices (Be clear and direct; Control the format of responses) Anthropic https://platform.claude.com/docs/en/build-with-claude/prompt-engineering/claude-prompting-best-practices 2026-10-31 Specific instructions about format and constraints are what can be verified
R2 Prompt engineering (guide) OpenAI https://developers.openai.com/api/docs/guides/prompt-engineering 2026-10-31 Recommends building tests and eval suites that measure prompt behaviour

Key terms (English ↔ Vietnamese)

English Tiếng Việt
Atomic requirement Yêu cầu nguyên tử (chỉ nói một điều)
Acceptance criteria Tiêu chí chấp nhận
Traceability Khả năng truy vết giữa yêu cầu và test
Requirement coverage Độ bao phủ theo yêu cầu
Registry Bảng tra cứu tên → hàm
Fail closed Khi không chắc, coi là lỗi thay vì coi là đạt