Early-bird price on the GenAI & Agentic AI Engineer Bootcamp batch. Grab a seat →

Prompt versioning means storing each prompt as a file in your repository, changing it only through a reviewed pull request, and recording with it the model identifier, the request settings and the evaluation results it was tested with. Every production request should carry the prompt version, so a change in behaviour can be traced to a release and undone with a revert.

This article is part of the LLMOps guide.

Key takeaways

  • A prompt version is the template text plus the model identifier, the settings and the tool definitions. Change any one and behaviour can change.
  • Prompts belong in files, not in string literals scattered through code or in a console that nobody reviews.
  • A prompt pull request should show the text diff and the evaluation results side by side.
  • Put the prompt name and version on every trace. OpenTelemetry defines gen_ai.prompt.name and gen_ai.prompt.version for this.
  • Rollback is a revert and a redeploy. It cannot undo a model retirement or data the new prompt already wrote.

What counts as a prompt version?

More than the words. The behaviour a user sees is produced by all of these together:

  • the system prompt and any template that wraps user input
  • few-shot examples
  • tool definitions (names, descriptions, parameters)
  • the model identifier
  • request settings such as the output token limit

If the template is unchanged but the model identifier moves from one model to another, you have a new version whether or not you gave it a number. Token counts can shift too: Anthropic notes that Claude 4.7 and later models use a newer tokenizer that produces roughly 30 per cent more tokens for the same text, so the same prompt has a different cost and a different context budget on a newer model.

Where should prompts live?

In the repository, one folder per prompt, with a small manifest beside the text.

{
  "name": "support-answer",
  "version": "2026-11-28.1",
  "model": "claude-sonnet-5-5",
  "max_tokens": 1024,
  "eval_report": "evals/reports/support-answer-2026-11-28.1.json"
}

A loader reads both files and returns everything the caller needs, including a hash of the text. The hash catches the case where someone edits the prompt and forgets to bump the version.

import hashlib
import json
import pathlib

def load_prompt(name: str) -> dict:
    folder = pathlib.Path("prompts") / name
    prompt = json.loads((folder / "manifest.json").read_text())
    text = (folder / "prompt.md").read_text()
    prompt["text"] = text
    prompt["sha"] = hashlib.sha256(text.encode()).hexdigest()[:12]
    return prompt

prompt = load_prompt("support-answer")
# Pass prompt["model"], prompt["max_tokens"] and prompt["text"] to the model call,
# and record prompt["name"], prompt["version"] and prompt["sha"] on the trace.

The alternative is a prompt registry: a managed service that stores prompts and serves them at run time. Amazon Bedrock, for example, has a Prompt management feature. The trade-off runs in both directions.

Prompts in the repositoryPrompts in a registry
ReviewPull requests, same as codeDepends on the tool's own approval flow
Change without a deployNoYes
Prompt and code change togetherYes, in one commitNo, they can drift apart
Non-engineers can editOnly through GitUsually yes
History and auditGit logThe tool's own history

Start with the repository. Move to a registry when people outside engineering need to edit prompts, and make sure it gives you review, history and a version identifier at run time.

How do you review a prompt change?

Like code, with one addition: the reviewer needs evidence, because reading a prompt diff does not tell you what the model will do.

  1. The author edits the prompt file and bumps the version in the manifest.
  2. CI runs the evaluation set and attaches the report. LLM evaluation in CI shows a workflow that does this.
  3. The reviewer reads the diff and the per-case results, especially cases that changed from pass to fail.
  4. The merge is blocked if thresholds are missed.

GitHub's CODEOWNERS file routes these reviews to the right people. A line such as the one below requests a review from a team whenever a pull request changes anything under prompts/:

/prompts/ @your-org/llm-reviewers

GitHub's documentation says the file can live in .github/, the repository root or docs/, that team owners need explicit write access, and that a branch protection rule can require review from code owners before merging.

Keep each pull request to one kind of change. If a prompt edit and a model upgrade land together and the score moves, you cannot say which one caused it.

A flow of six steps for a prompt change: edit the prompt file, open a pull request, run evaluations, review and merge, release with a version label, and monitor by version.

How do you tie a prompt to a model version and to eval results?

The manifest does most of the work: it names the model and points to the evaluation report produced for that exact combination. Three practices make it hold.

Keep the model identifier in the manifest, not in code. A model upgrade then becomes a reviewed manifest change that triggers the evaluations, instead of a constant edited somewhere in a client wrapper.

Track retirement dates. Anthropic says it gives at least 60 days' notice before retiring a publicly released model and that requests to a retired model fail. Its deprecations page lists a tentative retirement date for every model. Each prompt that names a deprecated model needs a new version, tested on the replacement, before that date.

Stamp every request. The OpenTelemetry generative AI conventions define gen_ai.prompt.name and gen_ai.prompt.version as span attributes, conditionally required when a named prompt template is used and a version is available. The version string can follow any scheme you choose. With those two attributes on every model call, a dashboard can split latency, cost and quality by prompt version. The conventions are still in Development status, so check the names against the version your tooling emits. LLM observability and tracing shows the instrumentation.

How do rollbacks work?

Revert the commit and redeploy. Because the prompt, the manifest and the calling code are in one repository, the revert restores a combination that was tested together.

Rollback has limits that are worth knowing before an incident.

  • It needs the old model. If the previous version named a model that has since been retired, reverting gives you failing requests.
  • It does not undo side effects. Summaries, tickets or database rows written by the faulty version stay written.
  • It resets the provider's prompt cache. Caching matches on an exact prefix, so both a release and a rollback change the prefix. The first requests afterwards are billed as cache writes, not reads. See how to reduce LLM costs.
  • It is only as fast as your deploy. If a redeploy takes an hour, consider a configuration switch that selects between the current and previous prompt versions, both already shipped.

What mistakes are common?

  • Editing a production prompt in a provider console or dashboard, with no review and no record.
  • Building prompts with string formatting spread across several functions, so no single file shows what is sent.
  • Putting changing values such as the current time at the top of the system prompt. It makes every request unique, which defeats prompt caching and makes outputs harder to compare.
  • Bumping the version without re-running evaluations, or re-running them without saving the report.
  • Versioning the prompt but not the tool definitions, which the model reads as part of its instructions.

Common questions

Should I use semantic versioning for prompts?

You can, but it is hard to say what a "breaking" prompt change is. A date-based identifier or a short content hash is simpler and just as traceable.

Do few-shot examples need versioning too?

Yes. They are part of the prompt, and changing one example can shift behaviour as much as changing an instruction.

How do I test a new prompt on real traffic safely?

Release it to a small share of requests, label every trace with the version, and compare error rate, cost and quality scores against the current version before widening the release.

Does a new model always need a new prompt?

Not always, but it always needs a new evaluation run. Treat "same prompt, new model" as a new version and let the results decide whether the text has to change.

Free download: LLM release evaluation kit

Build a regression suite for prompt, model, and workflow releases. Includes pass criteria, three worked test cases, and a run log you can use in release reviews. See what’s inside.

LLMOps: how to run LLM applications in production

What changes when you operate an LLM application: prompt and model versions, evaluations, tracing, cost per request and provider limits, with a minimum setup checklist.