A prompt edit is a production change. It alters outputs for every request that hits the path, and it usually ships with less review than a one-line code fix. This post describes a small process that treats prompts as deployable artifacts: versioned, evaluated, rolled out gradually, and reversible.
How prompt changes fail
Three failure modes show up repeatedly in reviews.
- Silent regression. A change fixes the three examples in the ticket and degrades a category nobody looked at. There is no baseline, so nobody notices for weeks.
- Untraceable output. A user reports a bad answer. The prompt has been edited twice since. You cannot say which text produced it.
- Coupled rollback. The prompt lives in a string inside the service. Reverting means a full deploy, so people hesitate and the bad version stays live longer.
All three come from the same cause: the prompt has no identity and no gate.
Step 1: Give every prompt a version
Store prompts outside application code, or at least in dedicated files, and give each revision an immutable identifier. A content hash works. A monotonically increasing integer works. A mutable name like latest does not.
What matters is the contract:
- A version is never edited after creation. Changes create a new version.
- Application code resolves a prompt by name plus an alias (for example
productionorcandidate), and the alias points at one version. - Every model call records the resolved version.
You can build this with a table and two columns, use a prompt registry in LangSmith, or keep files in git and resolve by tag. The tool matters less than the three rules.
from dataclasses import dataclass
@dataclass(frozen=True)
class PromptRef:
name: str
version: str # content hash or integer, never "latest"
def resolve(name: str, alias: str = "production") -> tuple[PromptRef, str]:
row = registry.get(name, alias) # your store
return PromptRef(name, row.version), row.template
Step 2: Stamp the version on every trace
Put the prompt name and version in trace metadata, next to the model name and any config that affects output. With LangChain you can pass it through the run config:
ref, template = resolve("support-answer")
chain.invoke(
inputs,
config={"metadata": {"prompt_name": ref.name, "prompt_version": ref.version}},
)
Now a bad answer maps to an exact prompt text, and you can slice quality, latency, and token spend by version.
Step 3: Gate on an eval delta
Before a candidate version gets any traffic, run it against your offline eval set and compare with the current production version on the same examples. Report the delta per slice, not only the aggregate. An aggregate gain of two points can hide a ten point loss on a small but important slice, such as questions with no answer in the corpus.
Set the gate in advance. For example: no slice drops more than a stated margin, and the aggregate does not fall. If you do not have an eval set yet, build one from production traces first. That is a prerequisite, not an optional extra.
Also check cost. A longer prompt with more few-shot examples raises input tokens on every call. Record the token delta alongside the quality delta.
Step 4: Shadow-run on real traffic
Offline sets go stale. Before switching, run the candidate on live requests without showing users the result.
- Duplicate a sample of requests to the candidate version, asynchronously, so user latency is unaffected.
- Store both outputs with the same request ID.
- Score pairs with your automated evaluators, and have a human read a sample of the disagreements.
Shadow runs double model spend for the sampled slice, so keep the sample small, often a few percent, and cap it. They are worth it when the prompt feeds tool selection or structured output, where failures are expensive. For low-stakes copy generation, the offline gate alone may be enough. Be honest about which case you are in.
Side effects need care. If the prompt drives an agent that calls tools, the shadow path must use stubbed or read-only tools. Otherwise you run every action twice.
Step 5: Roll out by alias, in stages
Move the production alias gradually: a small percentage of traffic, then a larger share, then all. Bucket by a stable key such as user or tenant ID so one user does not flip between versions mid-session. Define abort conditions before you start, such as a rise in schema validation failures, a drop in an online evaluator score, or a jump in tokens per request.
Because the alias lives in data, rollback is repointing it to the previous version. No deploy. Rehearse this once so it is a known operation, not an emergency improvisation.
What to watch after rollout
- Validation and parse failure rate for structured outputs.
- Tool-call error rate and average steps per run for agents.
- Refusal or empty-answer rate.
- Input and output tokens per request, and p95 latency.
- Evaluator scores on a sampled slice of live traffic.
Tie each to the version stamp from step 2. A regression that appears only after an alias move is easy to attribute.
Trade-offs
This process has costs. A registry adds a lookup on the hot path, so cache resolved versions with a short TTL. Aliases in a database are another thing that can be misconfigured. Small teams with one prompt and little traffic can get most of the value from git-tracked prompt files, version stamps in traces, and an offline gate. Add shadow runs and staged rollout when a bad prompt has real cost.
Pinning matters beyond prompts. The model version, temperature, and tool schemas change behavior too. If you can only stamp one more field, stamp the exact model identifier, because provider-side model updates can change outputs while your prompt stays fixed.
A minimal checklist
- Prompts are immutable versions resolved by alias.
- Every trace records prompt name, version, and model.
- Candidates must pass a per-slice eval delta and a token-spend check.
- Risky prompts get a capped shadow run with side effects disabled.
- Rollout is staged, bucketed by a stable key, with abort conditions written down.
- Rollback is an alias change that someone has practiced.