13.1 Template Architecture
# Production prompt template system
class PromptTemplate:
def __init__(self, template_id: str, version: str):
self.template_id = template_id
self.version = version
self.template = self._load_from_registry(template_id, version)
def render(self, **kwargs) -> str:
"""Render template with dynamic variables."""
return self.template.format(
context=kwargs.get("context", ""),
query=kwargs.get("query", ""),
history=kwargs.get("history", ""),
output_schema=kwargs.get("output_schema", ""),
)
# Usage
template = PromptTemplate("enterprise_qa", version="2.3.1")
prompt = template.render(
context=retrieved_chunks,
query=user_question,
history=conversation_history
)
13.2 Version Management Best Practices
- Semantic versioning for prompts (major.minor.patch)
- Major: Fundamental behavior change
- Minor: New capability or significant improvement
- Patch: Bug fix, wording optimization
- A/B testing framework for prompt variants
- Rollback capability — instant switch to previous version
- Audit trail — every prompt version change logged with rationale
- Performance tracking per version (quality score, cost, latency)
13.3 Prompt Registry Architecture
┌──────────────────────────────────────┐
│ Prompt Registry Service │
│ ┌────────────┐ ┌────────────────┐ │
│ │ Template │ │ Version │ │
│ │ Store (Git) │ │ Control (Git) │ │
│ └────────────┘ └────────────────┘ │
│ ┌────────────┐ ┌────────────────┐ │
│ │ A/B Test │ │ Metrics │ │
│ │ Router │ │ Dashboard │ │
│ └────────────┘ └────────────────┘ │
└──────────────────────────────────────┘
Process: prompts stored in Git with semantic versioning → CI pipeline runs an evaluation suite on every prompt change → canary deployment (5% → 25% → 100%) → automated rollback if quality metrics drop below threshold → per-client prompt variants stored as configuration → monthly prompt review and optimization cycle.
13.4 File-System Layout for Prompt Versioning
prompts/
├── claims_processing/
│ ├── v1.0_initial.md
│ ├── v2.0_structured_output.md
│ ├── v2.1_negation_handling.md
│ ├── v2.2_domain_specific.md
│ └── v2.3_confidence_scores.md ← current
├── denial_analysis/
│ └── v1.0_initial.md
└── evaluation/
├── test_cases.json
└── golden_dataset.json
Each prompt version includes: prompt text, expected-behavior description, test results against the golden dataset, author/reviewer approval, and a changelog.
Section 13 — Interview Q&A
Q: How do you version control and manage prompts in a production environment serving multiple clients/use cases? A: Prompts live in Git with semantic versioning, identical discipline to application code. Every prompt change triggers a CI pipeline that runs the full golden-dataset evaluation suite before merge. Deployment follows the same canary pattern as model rollouts — 5% → 25% → 100% traffic — with automated rollback if quality/cost/latency metrics regress. Per-client or per-use-case variants are stored as configuration referencing a specific template version rather than forking the template itself, keeping a single source of truth. I maintain an audit trail of every version change with the rationale, and a metrics dashboard tracking quality/cost/latency per prompt version over time so regressions are visible immediately rather than discovered by users.