11. Prompt Version Control
As prompts evolve through iteration, keeping track of changes becomes critical. Prompt versioning follows the same principles as code versioning but with unique challenges.
Prompt Storage Architecture
# prompts/customer-service/v2.3.yaml
version: "2.3"
created: "2024-03-15T14:32:00Z"
parent_version: "2.2"
model: "llama3:70b-instruct"
parameters:
temperature: 0.7
top_p: 0.9
template: |
You are a customer service representative for Acme Corp.
Policies:
- Refunds processed within 5 business days
- Escalation threshold: 3 prior contacts
Customer query: {query}
Response format:
1. Acknowledge the issue
2. Provide resolution timeline
3. Offer alternatives if applicable
changes_from_2.2:
- Added escalation threshold policy
- Changed response format to numbered list
Git-Based Prompt Management
Store prompts in git with structured diffs:
# Commit prompt changes with semantic versioning
git add prompts/customer-service/v2.3.yaml
git commit -m "feat: add escalation threshold, restructure response"
# View prompt history
git log --oneline --follow prompts/customer-service/v2.3.yaml
# Diff specific versions
git diff v2.1..v2.3 -- prompts/customer-service/v2.3.yaml
A/B Testing with Versioned Prompts
import random
from prompty import PromptRegistry
registry = PromptRegistry("prompts/")
def serve_prompt(prompt_name, context, traffic_split=None):
"""Route traffic between prompt versions."""
versions = registry.list_versions(prompt_name)
if traffic_split:
# Use specific version
version = traffic_split.get("version", versions[-1])
else:
# Random split for A/B testing
version = random.choice(versions)
prompt = registry.load(prompt_name, version)
return prompt.format(**context)
Rollback Strategy
When a new prompt version causes issues in production:
# Immediate rollback
kubectl set env deployment/prompt-service PROMPT_VERSION=v2.2
# Verify rollback
curl -X POST https://api.internal/health \
-d '{"check": "prompt_response_quality"}'
Local verification checkpoint
Run the smallest example from this chapter in a local workspace and record the package version, runtime, data path, and observed output. If the result depends on model size, vector count, CPU/GPU backend, or available memory, note that constraint beside the exercise so the lesson remains reproducible.
Set up a git repository for three prompts, create versions 1.0, 1.1, 1.2 for each with documented changes, then create a script that loads the latest version of any prompt by name.