Module: L1-M02 · Duration: ~150 min (estimate, including the independent exercise) · Previous: L04 · Next: Module exercises, then L1-M03 (LLM API Testing)
1. Introduction
In L04 you measured the impact of each small change. In a real project, a prompt change arrives as a change request: "v2: tighten the wording and add an example". The tester needs a repeatable process to answer the question: should the new version go to production?
This lesson puts everything in the module together into that process: store prompts by version, look at the diff, run the same test suite on both versions, classify the results, and write a change review with a recommendation.
2. Learning objectives
- Explain why prompts need version management like code, and why the model used must also be recorded.
- Read the diff between two prompt versions and predict which requirements may be affected.
- Run a change review and classify the results: fixed, broken, still failing, still passing.
- Detect a regression that is hidden by another regression (masking).
- Write an accept/reject recommendation backed by evidence.
3. Prerequisites and tools
4. Concepts
4.1 A prompt is code
OpenAI's guide recommends storing production prompts in the application's code, and building tests and an evaluation suite to measure prompt behaviour as you iterate. Before changing a production prompt, you should add representative fixtures, tests and checks [R1]. The consequences for the tester:
- Every prompt has an id and a version. The lab uses the form
MAJOR.MINOR.PATCH(1.0.0,2.0.0). Once a version has been released, any change that can alter behaviour should increase the major number. In the exercise, v2.1 is a fix of a v2 that was never released, so increasing the minor number is acceptable. - Prompt changes go through review, like a code pull request.
- Every test result records the prompt version used.
Everyday example. When a restaurant changes its prices, it prints a new price list with the date it applies from, and every bill is calculated from exactly one list. Nobody corrects the old list by hand without writing it down. When a customer complains, the restaurant knows at once which list that bill used.
4.2 The model is a variable too
The same prompt can behave differently on a different model, or on an update of the same model.
OpenAI recommends pinning production applications to a specific model snapshot, for example
gpt-4.1-2025-04-14, to make behaviour more consistent [R1]. For a tester, this means a test report
must record both: the prompt version and the exact model. L1-M06 returns to the topic of regression
when the model changes.
Everyday example. The same cake recipe in a different oven can burn. A good recipe note records the oven and the temperature, not only the ingredients.
Good vs bad. The first line of a test report:
| Weak report | Good report |
|---|---|
| "The new prompt passes 1/6." | "linguabot-tutor@2.0.0 on SimulatedTutor (the lab's simulation), 6 original cases TC-01 to TC-06, run on 2026-11-06: 1/6 passed." With a real model, record the exact snapshot name, for example gpt-4.1-2025-04-14 |
| Cannot be repeated: which prompt, which model, which case set? | Someone else can rerun exactly that configuration, and compare it with the next run |
4.3 The four outcomes of a change review
| Before (v1) | After (v2) | Classification | Meaning |
|---|---|---|---|
| FAIL | PASS | fixed | The change fixed a defect. That is its purpose |
| PASS | FAIL | broken | A regression. It must be explained or fixed before acceptance |
| FAIL | FAIL | still failing | An old defect, not fixed yet |
| PASS | PASS | still passing | Not affected (according to this test suite) |
Everyday example. Compare a pupil's report cards for two terms: a subject that went from fail to pass is progress, one that went from pass to fail needs a question at once, one that failed both terms is old work still not done. The overall average shows none of these three groups.
4.4 Masking: one defect hides another
When a change breaks the output format (for example by renaming a JSON key), every check after it fails for the same reason. The other defects still exist, but they are hidden. Once the format defect is fixed and the suite is run again, the hidden defect comes to light. That is why the change review must be run again after every fix; "the visible defect is fixed" does not mean the review is done.
Everyday example. When a motorbike has a flat tyre, the rattle of a loose chain is drowned out, because the whole bike shakes. Only after the tyre is fixed and the bike is ridden again do you hear the chain.
Worked example. Masking lives in the check results, not in the reply. Save the snippet below as
try_l05.py in the lab folder, run python try_l05.py, then delete the file:
from lab.checks import run_checks
from lab.prompt import PromptTemplate
from lab.simulated_model import SimulatedTutor
v2 = PromptTemplate.from_file("prompts/tutor_v2.json")
reply = SimulatedTutor().complete(v2.render(level="A2", learner_text="She go to school every day"))
print(reply)
for failure in run_checks(reply, {"required_keys": ["corrected", "explanation"],
"corrected_equals": "She goes to school every day."}):
print("FAIL", failure)
Output (copied from a real run on Python 3.14.6 and 3.12.3, Linux, 2026-11-06; both versions print the same):
{"fixed": "She went to school every day.", "explanation": "Động từ cần chia theo chủ ngữ."}
FAIL missing keys ['corrected']
FAIL corrected='<no corrected key>', expected 'She goes to school every day.'
Step by step: (1) the reply uses the key fixed, so required_keys fails; (2) corrected_equals fails
too, but only because there is no corrected key: the message says nothing about the tense; (3)
meanwhile the raw reply says She went to school, so the tense has changed. Both failure messages are
about the JSON key. Someone who reads only the check results misses the tense change; someone who also
reads the raw reply has a clue to verify in the exercise in §9.
4.5 Change review checklist
- What is in the diff? Which requirement does each changed line affect (L02)?
- Has any instruction been deleted or reworded? Which test protects it (L04)?
- Is there a new example? Does the example contradict the instructions or the output contract?
- Run the same test suite (and the matrix from L03) on both versions, then classify the results.
- Does every broken result have a cause yet? Could any defect still be hidden?
- Are the model and configuration the same between the two runs?
- Recommendation: accept, accept with conditions, or reject, with evidence.
Everyday example. A vehicle inspection station works through a fixed list (brakes, lights, emissions), even when the vehicle looks brand new. That is why two inspections of the same vehicle come out the same, whoever does them.
Good vs bad. Two comments on the same v1 → v2 change request:
| Weak review | Good review |
|---|---|
| "LGTM, v2 is shorter and has an example, so merge." | "Diff: removes 'Keep the learner's tense and meaning' (R2), removes the JSON key names (R1), adds an example with the key fixed (R1). Result: 5 broken (TC-01, TC-02, TC-03, TC-04, TC-06), all with the message missing keys ['corrected'], so another defect may be hidden. Model and configuration are the same. Recommendation: reject; fix the key, restore the keep-tense sentence, then run again." |
| No evidence; answers none of the checklist questions | Answers questions 1-7 of the checklist, with numbers |
5. Technical deep dive
5.1 prompt_diff
lab/review.py turns each version into indented JSON, then uses difflib.unified_diff (from Python's standard
library) to produce a diff like git diff. A line starting with - belongs to the old version, + to the
new version, and @@ -7 +7 @@ gives the line position.
5.2 change_review
The function runs the test suite on both versions, classifies the results with compare() (L02), collects the list of new failures,
and gives a verdict by one simple rule: if there is a regression, REJECT. This is the lab's rule,
not an industry standard. In practice, a small regression may be accepted in exchange for an important
fix. That decision belongs to people, based on risk, and the tester supplies the evidence.
6. The QA perspective
- What to test: every prompt change, including "just rewording" changes.
- Why: a prompt change can change behaviour without changing a single line of code. A CI pipeline that only runs the code tests will not catch it.
- What can go wrong: a hidden regression; comparing two runs on different models; a recommendation without evidence; accepting it "because it is only a prompt".
- Expected behaviour: no prompt change goes to production without a change review.
- How to detect it: the diff, running the suite on both versions, classification, then running again after every fix.
- How to report it: a one-page change review containing the diff, the classification table, the cause of each regression, the untested risks (for example R5 needs human review), the recommendation, and the configuration (prompt version, model).
7. Real-world scenarios
Scenario 1 - LinguaBot v2 (fictional; this is the lab). Change request: "tighten the wording and add an example". The review shows 5 regressions with one obvious shared cause (the JSON key). When the example is fixed to use the right key, another regression comes to light. You will do this yourself in the exercise.
Scenario 2 - A bank's internal copilot (fictional). The AI team changes the prompt and upgrades the model at the same time. The test pass rate drops from 95% to 88%. Nobody knows whether the cause is the prompt or the model. The lesson: change only one variable at a time (L04). Run the new prompt on the old model, then the old prompt on the new model, to separate the two causes.
8. Hands-on tutorial
8.1 Running the v1 → v2 change review
python -m lab.review
Actual output (2026-10-31):
--- linguabot-tutor@1.0.0
+++ linguabot-tutor@2.0.0
@@ -3 +3 @@
- "version": "1.0.0",
+ "version": "2.0.0",
@@ -7 +7 @@
- "Correct the grammar of the text inside <learner_text>. Keep the learner's tense and meaning.",
+ "Fix the grammar of the text inside <learner_text> so it sounds natural.",
@@ -10 +10 @@
- "Reply with a JSON object only, with the keys corrected and explanation."
+ "Reply with a JSON object only."
@@ -12 +12,6 @@
- "examples": [],
+ "examples": [
+ {
+ "input": "He like apples",
+ "output": "{\"fixed\": \"He likes apples.\", \"explanation\": \"Chủ ngữ 'he' cần động từ thêm -s.\"}"
+ }
+ ],
comparison: {'fixed': [], 'broken': ['TC-01', 'TC-02', 'TC-03', 'TC-04', 'TC-06'], 'still_failing': [], 'still_passing': ['TC-05']}
verdict: REJECT
In English, the Vietnamese explanation in the new example reads: "The subject 'he' needs the verb with -s added."
8.2 Reading the diff and linking it to requirements
| Changed line | Requirement affected (L02) | Prediction |
|---|---|---|
| Instruction 1 (the second line): "Keep the learner's tense and meaning" removed | R2 | The correction may change the tense |
| Instruction 4 (the last line): "with the keys corrected and explanation" removed | R1 | The JSON keys are no longer specified |
An example with the key fixed added |
R1 | The example may set a new key (L04) |
8.3 Reading the result
- 5 cases are broken, and all 5 report
missing keys ['corrected']. The obvious cause is the JSON key. - The right question at this point: once the key is fixed, is any other defect still hidden? The prediction table in 8.2 says R2 is at risk too. The exercise will verify that prediction.
You can also see the result of each case for both versions with python -m lab.runner v1 v2.
8.4 Running the tests
python -m pytest tests/test_review.py -v
Expected result: 4 passed. The whole lab: 41 passed (not counting tests you add yourself).
8.5 Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
| The diff is empty although the file was edited | The two files have identical content, the wrong path was read, or only a field starting with _ was edited (from_file ignores those fields) |
Check the path and the edited field; always increase version when editing |
KeyError in compare |
The two runs used different sets of cases | Compare on the same set of cases |
9. Independent exercise
Problem: A developer revises v2 into v2.1: it keeps every change from v2, but fixes the example to use the key
corrected. They say: "It's fixed, v2.1 can be released."
Requirements:
- Create
prompts/tutor_v2_1.json: copytutor_v2.json, changeversionto2.1.0, and fix the example so that its output uses the keycorrected. - Copy
exercises/test_l05_v2_1.pyintotests/, run it, then fill in the asserts according to the results you observe. - Write
reports/change-review-v2_1.md(at most one page) following the checklist in section 4.5, with an accept/reject recommendation and a specific proposed fix.
Test data: data/cases.json; prompts/tutor_v1.json; the v2.1 file you create.
Deliverable: the v2.1 prompt file, the test file, the change review.
Acceptance criteria: the v2.1 file differs from v2 only in version and the example; the test passes with the observed
results; the report points out the remaining regression, links it to the changed line that caused it, and explains why the previous
review did not see it.
Hint: look again at the prediction table in section 8.2.
9.1 Extra exercise: group failures by their first message to spot masking
Time: 15-30 minutes. File: exercises/test_l05_extra_masking.py.
Problem: When a change breaks the format, every case fails for the same first reason, and the real list of regressions is hidden behind it. Grouping the failing cases by their first failure message shows that at once: one very large group is a sign of masking.
Requirements:
- Copy the file into
tests/and runpython -m pytest tests/test_l05_extra_masking.py. Untouched, 4 tests fail withFailed: TODO: implement group_by_first_failure. - Write the body of
group_by_first_failure(results): return a dict{first failure message: [ids of the failing cases that start with that message]}. Passing cases are left out. - Run again until you get
4 passed. Look at the third test: without the JSON instruction, all 6 cases sit in one group. Write one sentence: when should a group that large make you rerun the change review after the fix?
Acceptance criteria: 4 tests pass; the function groups by failures[0], not by the whole list of
failures; passing cases do not appear in the result.
Hint: dict.setdefault(key, []).append(value) appends to a key's list, creating the list if it is
not there yet.
9.2 Real-world scenario: a prompt change and a model upgrade at the same time (fictional)
A company has an assistant called "HR Mate" (fictional) that answers questions about HR policy. This
week's release contains the prompt hr-assistant@3.0.0 (fully rewritten) and a new model. The
tester receives this table of results (each case run once):
| Case | Content | Before (prompt 2.3.0, old model) | After (prompt 3.0.0, new model) | First failure message (after) |
|---|---|---|---|---|
| HR-01 | Asks how many days of annual leave | PASS | PASS | |
| HR-02 | Asks for a colleague's salary | PASS | FAIL | reply is not valid JSON |
| HR-03 | Asks about maternity leave | FAIL | PASS | |
| HR-04 | Asks for the policy section number | PASS | FAIL | reply is not valid JSON |
| HR-05 | A question in English | PASS | FAIL | reply is not valid JSON |
| HR-06 | Asks for today's gold price (off-topic) | PASS | PASS | |
| HR-07 | Asks about the remote-work policy | FAIL | FAIL | missing section number |
| HR-08 | Asks about the Tet bonus policy | PASS | FAIL | reply is not valid JSON |
The product manager asks: "Can we release?"
Your task (45-60 minutes): write a change review of at most one page following the checklist in §4.5, ending with a recommendation.
A good answer has:
- All 8 cases placed in exactly one of the four groups in §4.3
- The sign of masking in the failure-message column spotted, and the case that would worry you most if a defect were hidden there named, with a reason
- The point that prompt and model changed at the same time, so the cause is unknown; a proposal to run the new prompt on the old model and the old prompt on the new model (§7, Scenario 2)
- A note that each case ran only once, while a real model needs repeated runs reported as a rate
- The configuration recorded: the prompt id and version, the exact names of both models
- A clear recommendation: do not release yet; separate the two changes, fix the format, then run the whole review again
10. Knowledge check
0/19 done · Results are kept in this browser only.
P02 · True or false
P03 · Short answer
Why must a test report for a prompt also record the exact model used?
P04 · Short answer
Explain "masking" with an example of your own, and say what must be done after the first defect is fixed.
P05 · Short answer
v3 fixes 2 old defects but causes 1 regression in a less important case. The lab's rule returns REJECT. How do you write the recommendation?
P06 · True or false
P07 · Match
P08 · Fill in the blank
P09 · Multiple choice
P10 · Spot the bug
The prompt_diff function below is copied from lab/review.py but has one defect. Find it.
def prompt_diff(old, new):
def lines(t):
data = asdict(t)
return json.dumps(data, ensure_ascii=False, indent=2).splitlines()
return list(difflib.unified_diff(lines(new), lines(old), f"{old.id}@{old.version}",
f"{new.id}@{new.version}", lineterm="", n=0))P11 · Recall
Lesson: L1-M02-L04P12 · Recall
Lesson: L1-M02-L01P13 · Essay
Write 4-6 sentences: for Scenario 2 in §7 (the AI team changes the prompt and upgrades the model at the same time, and the test pass rate drops from 95% to 88%), what do you propose doing to find the cause, and what should be done differently next time?
P15 · Multiple choice
P16 · True or false
P17 · True or false
P18 · Multiple choice
P19 · Apply now
Do the extra exercise in §9.1: copy exercises/test_l05_extra_masking.py into tests/, run python -m pytest tests/test_l05_extra_masking.py once before editing it, write the body of group_by_first_failure, then run it again.
11. Summary
- Concepts: a prompt is versioned code; the model is a variable that must be recorded; the four outcomes of a change review; masking; the review checklist.
- Skills: read a prompt diff; link changes to requirements; run and read a change review; run again after every fix; write a recommendation backed by evidence.
- Traps: treating a prompt change as "just rewording"; stopping at the first regression; changing the prompt and the model at the same time; letting an automated rule replace a human decision.
- You can now: review a prompt change request the way you review a pull request.
12. References
| ID | Title | Publisher | URL | Accessed | Relevance |
|---|---|---|---|---|---|
| R1 | Prompt engineering (guide) | OpenAI | https://developers.openai.com/api/docs/guides/prompt-engineering | 2026-10-31 | Store prompts in code; pin a model snapshot; build tests and evals before changing a production prompt |
| R2 | difflib - Helpers for computing deltas | Python Software Foundation | https://docs.python.org/3/library/difflib.html | 2026-10-31 | unified_diff, used in the lab |
Key terms (English ↔ Vietnamese)
| English | Tiếng Việt |
|---|---|
| Versioning | Quản lý phiên bản |
| Change request | Yêu cầu thay đổi |
| Change review | Đánh giá thay đổi trước khi chấp nhận |
| Regression | Lỗi mới xuất hiện ở thứ trước đây chạy đúng |
| Masking | Một lỗi che khuất lỗi khác |
| Pin a model snapshot | Cố định một phiên bản model cụ thể |
| Diff | Phần khác nhau giữa hai phiên bản |