Prompt Regression Testing
Freezing quality against change
Prompts need regression tests: golden inputs with expected behaviors, run on every change and every model swap. A prompt test suite is cheap insurance against silent quality rot.
What you will learn
- Build a golden prompt test suite
- Automate it in CI
- Gate model and prompt changes on suite results
What is this?
A prompt test suite holds representative inputs plus assertions: format validity, rule adherence, refusal behavior, banned claims absent. CI runs it on every prompt/model change. Because generation is stochastic, tests use seeds/low temperature, assertions relax (contains/validates/doesn't-contain), and flaky signals get statistical treatment.
Why do you need it?
- Prompts are user-facing; un-testled prompts rot quietly.
- Model upgrades silently detune prompts — the suite is the tripwire.
- Regression is generative: one bad example, reproduced everywhere.
- Fast, cheap, deterministic-enough — a handful of assertions beats a review argument.
Mental model
A smoke detector for the kitchen
Prompt regression tests
You don't smell-test the kitchen each morning; a detector checks continuously and loudly when something changes. Model upgrades are like swapping your oven — the same recipe may now burn, and the detector (suite) tells you before dinner is ruined.
How it works
- Collect 20-50 golden inputs: happy paths, edge cases, safety probes.
- Write assertions: output parses, required fields present, banned phrases absent, refusal when appropriate.
- Pin stable decode (low temp, seed) to reduce flake.
- Run in CI on every prompt diff and model bump.
- Treat failures as code failures: block the merge.
Test suite gates.
In production
- CI fails merges when a prompt stops producing valid JSON.
- Safety probes assert refusals for banned requests after every model bump.
- Golden format tests catch output-schema drifts before prod.
Best practices
- Write assertions on STRUCTURE and DO/DO-NOT rules, not exact text.
- Mix normal inputs with adversarial probes.
- Re-run on model upgrades with a publish gate.
- Store fixtures with the prompt, readable by humans.
Common mistakes
- Exact-match assertions on stochastic output (permanently red suite).
- Testing only happy-path formatting.
- Forgetting refusal/edge cases, so shipments pass on fluff.
Common issues
Suite 'always green' yet prod degradesGolden set skew (too easy)
Add edge/adversarial cases; sample real traffic.
Flaky failures block CIStochastic output + strict assertions
Pin decode settings; use contain/validate assertions with allow-lists.
Debugging tips
- Flaky test → decouple from random decode; set seed/low temp, or require relaxed contain.
- Suite green but users unhappy → golden set unrepresentative; enrich from traffic.
- Model bump kills 3 tests → re-tune those prompts before shipping.
Interview checkpoint
Hands-on lab
- Write a golden prompt suite with assertions
- Run it on two prompt candidates
- Decide ship/revert by results
Ship a Prompt Through a Gate
35 min · intermediate
Quick quiz
Prompt assertions should target…
Only prompt changes need the suite; model upgrades don't.