Prompt Versioning
Treat prompts as versioned artifacts with changelog, owner, and rollback.
In plain words
Prompt versioning keeps every version of your AI's instructions with notes about what changed and lets you switch back if a new version is worse.
Think of it like…
Legal contract templates in a law firm: each template has numbered versions, a change history, an approver and a rule that signed contracts record which version they used, so disputes can be resolved and a faulty clause can be withdrawn.
Where you’ve seen it
A support assistant's prompt support/answer lives in prompts/support/answer.md with front matter (id, version 15.0.0, owner, compatible models, variables customer_name, policy_chunks, output schema reference, eval run URL). Version numbers follow a convention: major when the output schema changes (consumers must adapt), minor for behaviour or instruction changes, patch for typos. The registry labels staging and production point to versions; the app calls get_prompt("support/answer", label="production"), caches it and logs prompt_id, version and an 8-character SHA-256 hash with every trace. A pull request for v15 shows a text diff and a generated comparison table against v14: tokens 2,400 → 3,200 (+800, which at $2.50 per million input tokens adds $0.002 per request, or $200 a day at 100,000 requests), overall pass rate 84% → 86%, refund slice 91.1% → 84.4% (−6.7 points, blocking), p95 4.9 s → 5.4 s. The author revises the wording and trims examples (v15.1: 2,700 tokens, refunds 90.0%, p95 5.0 s), the gates pass, the label moves to staging, then a canary, then production. When a later incident appears, the team traces affected requests by version and moves the production label back to v14 in seconds.
Words you’ll hear
- Immutable version
- A published prompt version that is never edited; changes create a new version.
- Label / alias
- A movable pointer such as production that selects a version.
- Content hash
- A fingerprint of the exact prompt text recorded in traces.
- Changelog and eval link
- Why it changed and the evidence for it.
Visual diagram
Theory & deep dive
What to version and how
A prompt artefact includes more than text: the template with named variables, system and user message structure, few-shot examples, the expected output schema or parser, model and parameter compatibility (temperature, max tokens) and the tool definitions it assumes. Version the bundle that determines behaviour. Use semantic versioning: major for incompatible output or variable changes (downstream code must change), minor for behavioural improvements, patch for non-behavioural edits. Record a content hash too: identical text yields the same hash, which detects silent edits and lets you deduplicate versions. Store prompts either in git (code review, history, CI, blame) or in a registry with UI for non-engineers; many teams sync them: the registry is the editing surface, git is the source of truth and a CI job validates and publishes.
At runtime, resolve prompts by name and label (not by hard-coded text), cache them with a short TTL and fall back to a bundled known-good version if the registry is unreachable. Log prompt_id, version and hash on every trace and metric so you can slice quality, cost and latency by version and reproduce any request. Keep variables validated (a missing policy_chunks should fail loudly rather than send a broken prompt) and test rendering in CI with sample inputs.
id: support/answer, version: 15.1.0, owner: support-ai@, models: [model-a, model-b], variables: [customer_name, policy_chunks], output_schema: schemas/answer.json, eval_run: ci/runs/4812, changelog: Trim examples; clarify refund-window wording.
Review, release and rollback
A prompt change goes through the same discipline as code: a pull request with a readable diff, automated evaluation against the golden set (overall, per-slice, safety, latency) and a cost comparison (token counts and dollars per request: +800 tokens at $2.50 per million input tokens is +$0.002 per request, $200 a day at 100,000 requests), review by an owner and, for sensitive prompts, a domain expert. Move the staging label first, run integration checks, then release with a canary or percentage rollout (see canary and feature-flag lessons) and the production label. Keep all prior versions available and make rollback a label move (seconds, no deploy). Archive the evaluation results with the version so you can explain why a version shipped.
Handle schema changes carefully: when a new major version changes the output format, support both formats in consumers during the transition (expand/contract) and don't flip the label until the parsers are deployed. Manage model coupling: a prompt tuned for one model may degrade on another, so record compatibility and re-evaluate on model upgrades (see model versioning). Avoid shadow prompts (text edited in a vendor UI without version control, or built from string concatenation in code) by centralising prompt construction, and restrict who can change production labels with audit logs. Periodically prune unused versions, review prompts with growing token counts (bloat raises cost and latency) and keep documentation of prompt purpose and known failure modes.
Incident at 14:02: refund answers are wrong. Trace filter prompt_version=15.1.0 shows the spike. At 14:07 the on-call moves production from v15.1.0 back to v14.2.0. Caches refresh within 60 seconds; the error rate returns to baseline by 14:10, with no redeploy.
How it works, step by step
Step 1 of 41. Define the artefact and conventions
Choose git or a registry, a front-matter schema, semantic versioning rules and labels for environments.
- Immutable
- versions
When to use it & trade-offs
What it is
Prompt versioning treats prompts as versioned, reviewable, testable artefacts rather than strings buried in code or edited in a dashboard. Each prompt has an identifier, an immutable version (semantic version or content hash), an owner, a changelog entry, its variables and output schema, compatible models, links to eval results and cost metrics, and labels such as staging and production that point to a version. Prompts live in git (files with front matter) or a prompt registry (Langfuse, LangSmith and similar), the application resolves a prompt by name and label at runtime, and every trace records the prompt id, version and content hash so any output can be traced to the exact text that produced it.
Why it matters: A one-word prompt edit can shift behaviour, cost and latency for every user, and without versioning nobody can say what changed, who approved it, whether it was evaluated or how to undo it. Versioning gives reviewable diffs, reproducible incidents, instant rollback, safe experiments (A/B or canary between versions) and a shared source of truth between engineers, product and domain experts who edit prompts.
When to reach for it
- Any production prompt that affects users or cost
- Multi-team prompt editing with approvals
- Experimenting with prompt variants
When to avoid or be careful
- Editing production prompts in place
- Prompts defined by ad-hoc string concatenation across files
- Releasing prompt changes without eval and cost comparison
Where prompts live
Strengths: Familiar tooling; diffs; blame.
Watch out: Less friendly for non-engineers.
Strengths: UI; label moves without deploy; links to traces and evals.
Watch out: Another dependency; must sync with git.
Strengths: Fast to start.
Watch out: No history, review or rollback separate from code.
Interview signals & numbers to know
When this topic comes up
- “What prompt produced that answer?”
- Prompt registry and labels
- Semantic versioning for prompts
- Rollback by label
- Prompt bloat
Benchmarks & rules of thumb
- +800 tokens
- adds $0.002 per request at $2.50 per million
- $200/day
- extra cost at 100,000 requests a day
- 8 characters
- short content hash recorded in each trace
Common mistakes & follow-ups
Common interview mistakes
- Changing a prompt without recording the version in traces.
- Letting prompt token counts grow release after release.
- Forgetting to update parsers when the output schema changes.
Likely interviewer follow-ups
- How would you manage prompt changes across a team?
- How do you roll back a bad prompt quickly?
- What metadata should a prompt version carry?
Knowledge check
Put it into practice
Practice related interview Q&A
Apply Prompt Versioning with generative AI interview Q&A and hands-on practice.