Prompt
I'm building a multi-model app and need prompt management across environments
Latest observation
A good way to manage prompts across environments in a multi-model app is to treat prompts like versioned application assets, not hardcoded strings.
Recommended approach
1) Store prompts externally
Keep prompts in a central prompt registry instead of embedding them directly in code.
Common options:
- Config files: YAML / JSON / TOML in git
- Database-backed prompt store: useful for runtime updates
- Dedicated prompt management service: if you need approvals, audit logs, A/B tests, or non-engineer editing
A simple structure might be:
name: customer_support_reply
version: 3
models:
openai:gpt-4.1:
template: |
You are a support assistant...
User issue: {{issue}}
anthropic:claude-sonnet-4:
template: |
...
environments:
dev:
enabled: true
staging:
enabled: true
prod:
enabled: true
2) Separate prompt content from environment config
Use environment-specific settings for:
- model IDs
- temperature/top_p
- max tokens
- tool availability
- safety policies
- fallback model order
Example:
- Dev: cheaper model, verbose logging, relaxed rate limits
- Staging: production-like model, test data only
- Prod: locked versions, monitoring, strict policies
3) Version prompts explicitly
Every prompt should have:
prompt_idversionstatus(draft,active,deprecated)ownerchange notes
This lets you:
- roll back safely
- compare versions
- pin a specific prompt in prod
4) Use a templating system
Design prompts with variables rather than concatenated strings.
Example:
You are a helpful assistant.
Context:
{{context}}
Question:
{{question}}
Then validate required variables before sending to a model.
5) Add environment overlays
Keep a base prompt and override only what differs.
For example:
prompts/base/customer_support.yamlprompts/dev/customer_support.yamlprompts/prod/customer_support.yaml
Or:
- base prompt in registry
- env-specific settings layered on top
6) Pin production to immutable versions
In production, don’t point to “latest” unless you have strong controls. Use:
- exact prompt version
- exact model version
- exact tool config
This prevents accidental changes from affecting users.
7) Add evaluation and rollout controls
Before promoting a prompt:
- run offline evals
- compare against baseline
- do canary release or A/B test
- monitor output quality, latency, cost, and safety
8) Build observability in
Log:
- prompt ID and version
- model used
- environment
- input variables
- output metadata
- token usage
- latency
- error/fallback reason
Be careful not to log sensitive data unless protected.
A practical architecture
Option A: Git-backed prompt registry
Best for teams that want simplicity and code review.
- Prompts stored in repo
- CI validates syntax and required variables
- Deploy pipeline publishes to envs
- Prod uses pinned versions
Pros:
- easy version control
- good review workflow
- simple rollback
Cons:
- less dynamic at runtime
Option B: Database + admin UI
Best if product/ops teams need to edit prompts without deploys.
- prompt definitions in DB
- admin UI for edits/approvals
- API serves prompt by
id + env + version - cache locally for latency
Pros:
- flexible
- runtime updates
Cons:
- more engineering and governance needed
Suggested minimal schema
{
"prompt_id": "customer_support_reply",
"version": 3,
"environment": "prod",
"model": "openai:gpt-4.1",
"template": "You are a support assistant... {{issue}}",
"variables": ["issue"],
"temperature": 0.2,
"status": "active"
}
Good practices
- Keep prompts small and focused
- Use one prompt per task
- Don’t mix environment logic into the prompt text
- Validate prompt variables at build time
- Track prompt changes like code changes
- Maintain test cases for each prompt
- Prefer deterministic settings in prod when possible
If you want, I can give you one of these next:
- a reference architecture for prompt management across dev/staging/prod
- a Git-based folder structure example
- a database schema + API design for a prompt registry
- a Python/TypeScript implementation for loading prompts by environment and model