Prompt Engineering
Advanced 13 min read Prompt Engineering

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.

prompt testingregressiongolden teststest suitemodel swap
Prerequisites: System Prompts
Before we start

What you will learn

  • Build a golden prompt test suite
  • Automate it in CI
  • Gate model and prompt changes on suite results
Introduction

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.

Motivation

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.
Think about it

Mental model

Imagine

A smoke detector for the kitchen

Think of

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.

Mechanics

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.

Change
Run suite
Gate
Green
Real world

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.
Guidelines

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.
Watch out

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.
Root cause analysis

Common issues

Error
Suite 'always green' yet prod degrades
Root cause

Golden set skew (too easy)

Fix

Add edge/adversarial cases; sample real traffic.

Error
Flaky failures block CI
Root cause

Stochastic output + strict assertions

Fix

Pin decode settings; use contain/validate assertions with allow-lists.

When things break

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.
Interviews

Interview checkpoint

Practice

Hands-on lab

Ship a Prompt Through a Gate
35 min · intermediate
In progress
Objectives
  • 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

0/4 steps
0%
sandbox · Linux sandbox
$
Try these commands
Test yourself

Quick quiz

0/2
1

Prompt assertions should target…

2

Only prompt changes need the suite; model upgrades don't.

Go deeper

Official documentation