Sub topic 10
Reviewing and Releasing a New Prompt Version
This chapter covers how a new prompt version moves from a draft to production. It assumes you already have the earlier pieces: templates stored as files under prompts/<name>/<version>.yaml, a version number and change note in each file, a pin that selects the version in use, and a small regression suite. Here you connect them into one release process with checks, a human review, a staged rollout, and a rollback path.
Why prompts need a release process
A prompt change looks like a text edit, but its effect is a change in program behavior. Fixing one phrase can alter output length, tone, or format for every user. Three things make prompt releases risky:
- The effect is hard to predict from the diff. A one-word edit can change results on inputs you never thought about.
- Model output is not deterministic, so a single manual try proves little.
- Downstream code often depends on the output format. A prompt that now answers in two sentences can break a parser that expects one.
A release process cannot remove these risks. It makes them visible before users see them, and it makes the change reversible afterward.
The stages of a release
A release has five stages. Each stage can stop the release.
Cheap checks run first and slow ones later. A malformed file should never consume model calls or a reviewer's time.
Stage 1: Automated file checks
A new version is a new file. The first checks look only at that file and at the version it replaces. They need no model call.
The script below verifies four things:
- The file's
versionfield matches its file name. - A non-empty
changelogis present. - The declared
variablesmatch the placeholders in the template body. - The version number is higher than the one currently pinned.
import yaml
from pathlib import Path
from string import Template
REQUIRED_KEYS = {"name", "version", "changelog", "variables", "template"}
def load_prompt(name, version):
path = Path("prompts") / name / f"{version}.yaml"
return yaml.safe_load(path.read_text())
def placeholders(template_text):
names = set()
for match in Template.pattern.finditer(template_text):
name = match.group("named") or match.group("braced")
if name:
names.add(name)
return names
def parse_version(text):
return tuple(int(part) for part in text.split("."))
def check_candidate(name, candidate_version, pinned_version):
problems = []
prompt = load_prompt(name, candidate_version)
missing_keys = REQUIRED_KEYS - prompt.keys()
if missing_keys:
return [f"missing keys: {sorted(missing_keys)}"]
if prompt["version"] != candidate_version:
problems.append("version field does not match file name")
if not str(prompt["changelog"]).strip():
problems.append("changelog is empty")
if placeholders(prompt["template"]) != set(prompt["variables"]):
problems.append("declared variables differ from template placeholders")
if parse_version(candidate_version) <= parse_version(pinned_version):
problems.append("version is not higher than the pinned version")
return problemsTemplate.pattern is the regular expression that string.Template itself uses, so this check agrees exactly with what substitute will accept. A hand-written regex could disagree on edge cases such as $$ for a literal dollar sign.
Compare versions as tuples of integers, not as strings. As strings, "1.10.0" sorts before "1.9.0".
Released versions are immutable
Once a version has been pinned anywhere, its file must never change. If 1.2.0 is edited in place, logs that say "ran 1.2.0" no longer identify one text. Enforce this in CI by failing when an existing version file is modified or deleted:
# Fails if a version file that already exists on main was changed or removed.
if git diff --name-status origin/main -- prompts | grep -E '^(M|D)'; then
echo "Released prompt versions are immutable. Add a new version instead."
exit 1
figrep exits with status 0 when it finds a match, so the if branch runs only when something was modified or deleted.
Stage 2: The regression gate
The regression suite from the previous chapter returns a list of failures for one version. A release gate runs it on both the pinned version and the candidate and compares the results.
Compare the two failure lists instead of requiring an empty list. Some cases may already fail on the current version. Those are known problems and should not block an unrelated improvement. A case that passes today and fails with the candidate is a regression, and it blocks the release.
def gate(baseline_failures, candidate_failures):
baseline = set(baseline_failures)
candidate = set(candidate_failures)
return {
"regressions": sorted(candidate - baseline),
"fixed": sorted(baseline - candidate),
"still_failing": sorted(candidate & baseline),
}
baseline = [("The meeting moved to Friday.", "Friday")]
candidate = [("Cats sleep a lot.", "cat")]
report = gate(baseline, candidate)
print(report)
if report["regressions"]:
raise SystemExit("Release blocked: candidate fails cases the pinned version passes.")Each failure is a (text, word) pair, the same shape run_suite returns, so the gate works directly on its output. The sample data above shows a candidate that fixes one case and breaks another. That candidate is blocked even though its failure count is the same as the baseline's.
Two details matter in practice:
- Run the suite with the same model and settings that production uses. A pass at a different temperature or on a different model does not carry over.
- If outputs vary between runs, run each case several times, or set the temperature to 0 for the suite. Otherwise the gate will occasionally fail with no change in the prompt.
A keyword suite catches only coarse breakage. Treat a green gate as "nothing obvious broke," not as proof of quality. The human review covers the rest.
Stage 3: Human review
Reviewers need two things: what changed in the text, and what changed in the outputs. The Git diff shows the first. The gate report and a sample of outputs show the second.
A useful review request includes:
- The diff between the pinned version file and the candidate.
- The
changelogline, which states the intent so the reviewer can judge whether the diff matches it. - The gate report: regressions, fixed cases, and still-failing cases.
- Before and after outputs for a few real inputs, including at least one unusual one.
Reviewers can work from a checklist:
| Question | What to look for |
|---|---|
| Does the diff match the changelog? | Unmentioned edits, such as a removed rule or a new instruction |
| Did the variables change? | Added or removed variables require changes in calling code |
| Is the output format preserved? | Parsers, length limits, and downstream schemas |
| Is untrusted input still isolated? | User text placed inside instructions instead of in a delimited section |
| Is the version bump correct? | A change to variables or output format should be a larger bump than a wording fix |
| Are new cases needed? | Each bug fixed by this version should add a regression case |
The last row is easy to skip and valuable. A bug that was fixed without a test case can return in a later edit with nothing to catch it.
Stage 4: Staged rollout with pins
Releasing means changing a pin, not replacing a file. Because the candidate file already exists in the repository, you can pin it in one environment first and leave the others unchanged.
Keep pins in a data file, one entry per environment, so a release is a small reviewable diff:
summarize:
staging: 1.3.0
production: 1.2.0The application reads the pin for its own environment:
import os
import yaml
from pathlib import Path
def pinned_version(name, environment=None):
environment = environment or os.environ.get("APP_ENV", "production")
pins = yaml.safe_load(Path("pins.yaml").read_text())
return pins[name][environment]The release then has two steps, each its own small pull request:
- Merge the new version file together with the staging pin. Run real or replayed traffic against staging and read the logs.
- After staging looks sound, change the production pin to
1.3.0.
If you need to limit exposure further, pin a single instance or a percentage of traffic to the candidate first. This requires your serving code to choose a version per request, and it requires logging the version on every call. Without the log, you cannot tell which requests used which version.
Pins can also be aliases such as stable or latest, as discussed in the pinning chapter. For production, resolve the alias to a concrete version at deploy time and log the concrete number. An alias that moves silently makes incidents hard to reconstruct.
Stage 5: Monitoring and rollback
After the production pin changes, watch the signals that a regression would affect. These are typically parse failures, output length, refusal rate, user complaints, and cost per call. Compare them by prompt_version, using the field you log with each model call.
Rollback is the reverse of release. Change the pin back to the previous version and deploy:
summarize:
staging: 1.3.0
production: 1.2.0This works because 1.2.0 is immutable and still in the repository. You do not need to revert a commit or rebuild a prompt from memory. Decide in advance who may roll back and under what conditions. A rollback should not need the original author or a full review round, since speed is the point.
After a rollback, do the follow-up work. Add a regression case that reproduces the failure, fix the candidate as a new version such as 1.3.1, and run the process again. Do not edit 1.3.0.
Common release mistakes
- Changing the pin and the code together. If a new prompt version needs new variables, the calling code must supply them. Release them as one change, or make the code compatible with both versions first and then switch the pin. Otherwise
substituteraisesKeyErrorin production. - Testing a different configuration. The suite ran at temperature 0 on one model, and production runs at temperature 0.7 on another. The gate result does not apply.
- Skipping the changelog on small edits. Small edits are the ones people later cannot explain.
- Reusing a version number after a rollback. Numbers are never reused, even for a version that was never fully released.
- Letting the suite shrink. Removing a failing case to get a green gate defeats the purpose. Removals should be reviewed like any other change.
Exercise
A candidate version 1.3.0 of summarize passes all regression cases that 1.2.0 passes, and it also fixes one case that 1.2.0 failed. A teammate suggests editing the 1.2.0 file to include the same fix instead of releasing a new version, since "it is the same prompt." Give two reasons this is a bad idea.
Show answer
First, logs that record prompt_version: 1.2.0 would no longer identify one text, so past outputs could not be traced to the prompt that produced them. Second, rollback depends on 1.2.0 staying unchanged. If it were edited, rolling back would not return to the behavior that was known to work. A new version 1.3.0 keeps both properties, and the immutability check in CI would reject the edit anyway.
Exercise
Write the output of gate(baseline, candidate) for the lists below, and say whether the release is blocked.
baseline = [("A", "x"), ("B", "y")]
candidate = [("B", "y"), ("C", "z")]
Show answer
The result is {"regressions": [("C", "z")], "fixed": [("A", "x")], "still_failing": [("B", "y")]}. The release is blocked because ("C", "z") fails with the candidate but not with the baseline. The still-failing case ("B", "y") does not block the release because it already failed before.