Prompt Versioning
Prompts are code. Version them, review changes, and test before deploying. This guide covers prompt templates, a versioning strategy that fits a Git workflow, and how to A/B test prompt variants in production.
Why Version Prompts
Changing a prompt changes your product behaviour. Without versioning, prompt changes are invisible in your git history, impossible to roll back quickly, and hard to attribute to output quality changes.
Templates
Store prompts as template strings with typed variable slots. Keep them in a dedicated file so changes are diffable.
// v1 — baseline
export const SUMMARIZE_V1 = (text: string) =>
`Summarize the following in 2–3 sentences:\n\n${text}`;
// v2 — added format constraint
export const SUMMARIZE_V2 = (text: string) =>
`Summarize the following in exactly 2 sentences. \
Use plain language. No bullet points.\n\n${text}`;
// Active version — swap this to roll out a change
export const summarize = SUMMARIZE_V2;Version Strategy
Add a new versioned export (SUMMARIZE_V3) alongside the existing ones. Never edit existing versions in place.
Use your eval pipeline to score the new version against the current one on your standard dataset. Both scorers run in the same pass.
Open a pull request. The diff shows exactly what changed in the prompt text. Reviewers can comment line by line.
Change the active export to the new version. One line diff. Easy to revert with git revert.
A/B Testing
Route a percentage of traffic to the new prompt version and compare live metrics before fully rolling out.
export function summarize(text: string, userId: string): string {
// Deterministic split: same user always gets same variant
const isVariant = parseInt(userId.slice(-2), 16) < 0x1a; // ~10%
if (isVariant) {
return SUMMARIZE_V3(text); // new prompt
}
return SUMMARIZE_V2(text); // control
}