How a prompt change is versioned, evaluated and promoted
Step 1 of 5
Edit in git
The change lives in version control as a new tagged version, such as 1.1.0, instead of being edited in a notebook or a dashboard.
Step 2 of 5
Run evals
CI runs the candidate against the golden set and records a score. The earlier version's score is already stored for comparison.
Step 3 of 5
Promotion gate
If the candidate scores lower than the current version, promotion raises a regression error and the old prompt stays in place.
Step 4 of 5
Canary rollout
A small share of live traffic uses the new version while metrics are tracked per prompt version, so a problem shows up on a few users rather than all of them.
Step 5 of 5
Rollback
Because every version is pinned and kept, rolling back means selecting the previous version, which can happen within minutes.
Treat a prompt like code: no promotion without a score, and a quick way back.
Problem
Prompts are code. Editing a prompt in a notebook breaks production, cannot be rolled back, and cannot be evaluated across versions.
Pattern
Version prompts as code. Tag, evaluate and deploy prompt versions through the same pipeline as application code.
Implementation
prompt_versioning.py
~199 tokens
from dataclasses import dataclass
@dataclass
class PromptVersion:
id: str
template: str
version: str
eval_score: float
PROMPTS = {
"rag_answer": [
PromptVersion("rag_answer", v1_template, "1.0.0", 0.72),
PromptVersion("rag_answer", v2_template, "1.1.0", 0.81), # current
],
}
def get_prompt(name: str, version: str = "latest") -> str:
versions = PROMPTS[name]
if version == "latest":
return versions[-1]
return next(v for v in versions if v.version == version)
# Evaluate new prompt in CI before promoting
def promote_prompt(name, candidate):
score = run_eval(name, candidate)
if score < current_score(name):
raise EvalRegressionError(score)
PROMPTS[name].append(candidate)