Lesson 14 of 15 · In Production
Testing and Versioning Prompts
Test prompts like code: build a test set from real inputs, check outputs with rules or an AI judge, compare versions, catch regressions and version changes.
- 7 min read
- Beginner
- Reviewed
- Why a prompt that works once is not the same as a prompt that works
- How to build a test set and decide what counts as a pass
- Three ways to check outputs: exact answers, rules in code and an AI judge
- How to version prompts so you can compare and roll back
"It worked when I tried it"
A prompt that gives a good answer once has passed one test. Real use brings hundreds of different inputs: short and long, polite and angry, in different languages, with typos and odd requests. A prompt for regular or business use needs testing across that range.
There is a second reason. When you change a prompt to fix one problem, you can quietly break something that used to work.
Build a test set
A useful test set:
- Starts small: 20 to 50 cases is a good start; grow it over time.
- Uses real inputs wherever possible, with private details removed.
- Covers the variety: common cases, rare cases, long and short inputs, different languages if relevant.
- Includes edge cases and past failures: every time a prompt fails in real use, add that input to the test set.
- Says what a pass is for each case.
Three ways to check outputs
| Check | How | Good for |
|---|---|---|
| Exact answer | Compare with the known correct answer | Labels, yes/no, numbers, extracted fields |
| Rules in code | Program checks length, format, valid JSON, required or banned words | Format and constraints |
| AI judge | Another prompt scores the output against a rubric | Tone, helpfulness, accuracy of a summary |
The program below compares two versions of a classification prompt on a five-case test set, using exact answers plus a format check. The outputs were recorded from running each version.
allowed = ["billing", "bug", "feature request"]
# The test set: real inputs with the label a good answer must give
tests = [
("I was charged twice for March", "billing"),
("The app crashes when I upload a photo", "bug"),
("Please add a dark mode", "feature request"),
("Why is my invoice in dollars, not euros?", "billing"),
("Export button does nothing and I need my data for my tax bill", "bug"),
]
# What each prompt version returned for those inputs (recorded from real runs)
outputs = {
"v1": ["billing", "Bug", "feature request", "The topic is billing.", "billing"],
"v2": ["billing", "bug", "feature request", "billing", "bug"],
}
for version in outputs:
passed = 0
for i in range(len(tests)):
message, expected = tests[i]
got = outputs[version][i]
if got == expected:
passed += 1
elif got not in allowed:
print(f" {version} test {i + 1}: format problem, got {got!r}")
else:
print(f" {version} test {i + 1}: wrong label, got {got!r}, expected {expected!r}")
print(f"{version}: {passed}/{len(tests)} passed ({passed / len(tests):.0%})")Version 1 has three failures, and the report says why: two are format problems (a capital letter, a whole sentence) and one is a real wrong label. That tells you what to fix: version 2 added "Reply with exactly one of: billing, bug, feature request, in lower case" and an example for messages that mention money but describe a bug.
Versioning prompts
Treat important prompts like code:
- Store them in files in version control (such as Git) or a prompt management tool, not in someone's notes.
- Give each change a version, such as v1, v2, v3, with a short note: what changed, why, and its test score.
- Record the model and settings used with each version, because the same prompt can behave differently on another model.
- Keep the old versions, so you can roll back if a new one causes problems in real use.
v3 (2026-11-12) model: small-fast, temperature 0
Added: "If the message mentions money but describes something broken,
choose bug." Fixes 2 test failures. Test set: 48/50 (was 46/50).Common mistakes
Compare two prompt versions on the same test set and pick the winner.
# True means the test passed
results = {
"v1": [True, False, True, True, False],
"v2": [True, True, True, False, True],
}
# For each version print its score like: v1: 3/5 (60%)
# Then print the version with the most passes like: Best: v2
You improve a prompt to fix one bad answer. What should you do before using the new version?
Summary
- One good answer is one passed test; real prompts need a test set of varied, real inputs and edge cases.
- Check outputs by exact answer, rules in code or an AI judge with a rubric.
- Run the full set after every change to catch regressions, and add every real failure to it.
- Version prompts with notes, test scores, the model and settings, and keep old versions to roll back.
Next: prompt injection, the security risk every prompt-based app must understand.
Finished reading? Tick it off to track your progress.