Prompt
How do I manage prompts in CI/CD for an LLM app?
Latest observation
A good way to manage prompts in CI/CD for an LLM app is to treat prompts like production code: version them, test them, review them, deploy them gradually, and monitor them continuously.
Here’s a practical setup.
1) Store prompts in version control
Keep prompts in Git, not buried in app code or a UI only.
- Use separate files per prompt, e.g.:
prompts/summarize.mdprompts/support_agent.yamlprompts/rag_answer.txt
- Include metadata with each prompt:
- name
- version
- owner
- intended model
- expected inputs/outputs
- safety constraints
Example:
name: support_reply
version: 3
model: gpt-4.1
system: |
You are a support assistant. Be concise and polite.
user_template: |
Customer issue: {{issue}}
constraints:
- Do not promise refunds
- Escalate billing disputes
2) Use prompt templates, not hardcoded strings
Parameterize prompts so changes are controlled and testable.
- Use templating tools like Jinja2, Mustache, Handlebars, etc.
- Keep business data separate from instructions.
- Validate required variables before sending the prompt.
3) Add prompt tests in CI
Create automated checks that run on every pull request.
Types of tests:
- Format tests
- required sections exist
- no missing template variables
- token length within limits
- Golden tests
- compare outputs for a fixed set of inputs
- ensure expected behaviors don’t regress
- Behavioral evals
- check rubric-based scoring
- safety, correctness, tone, policy compliance
- Red-team tests
- prompt injection attempts
- jailbreaks
- toxic / unsafe inputs
Example CI checks:
- prompt loads successfully
- all templates render
- outputs pass schema validation
- eval score stays above threshold
4) Use automated evaluation pipelines
Instead of relying on manual review, create a repeatable evaluation suite.
Common metrics:
- task success rate
- factuality / groundedness
- format adherence
- refusal correctness
- latency
- cost per request
For example, if a prompt changes:
- run 100 test cases
- compare old vs new prompt
- fail build if accuracy drops by >5%
- warn if cost or latency increases too much
5) Gate prompt changes with code review
Require PR review for prompt edits, just like code.
Reviewers should check:
- does the prompt change the intended behavior?
- is the instruction clear and minimal?
- any safety or compliance concerns?
- does it conflict with other prompts or tools?
- is the prompt robust to user input manipulation?
6) Version prompts and support rollback
Prompts should be deployable like app releases.
- Tag prompt versions:
support_reply@v3 - Keep changelogs for prompt updates
- Make rollback easy if a new prompt regresses
- Use feature flags or config flags to route traffic to prompt versions
A common pattern:
- deploy
v4to 5% of traffic - monitor quality
- promote to 100% if healthy
- rollback to
v3if metrics drop
7) Separate environment-specific configuration
Prompts often vary by environment:
- dev: verbose, debug-friendly
- staging: production-like data and limits
- prod: locked down, safe defaults
Keep model name, temperature, tools, and prompt version in environment config so you can reproduce behavior.
8) Monitor prompts in production
CI/CD doesn’t end at deployment.
Track:
- user satisfaction
- fallback rate
- refusal rate
- hallucination / grounding issues
- tool-call success rate
- cost and latency
- prompt-injection incidents
Log:
- prompt version
- model version
- input/output traces
- eval scores
- errors and safety events
9) Use a prompt registry or management layer
As the system grows, a registry helps manage prompts centrally.
This can be:
- a YAML/JSON prompt manifest in Git
- a prompt management service
- a LangChain/LlamaIndex-style abstraction
- your own internal registry with versioning and approvals
Useful features:
- semantic versioning
- approvals
- rollout tracking
- A/B testing
- audit logs
10) Secure the prompt supply chain
Prompts are part of your attack surface.
Protect against:
- unauthorized prompt edits
- dependency drift
- accidental secret leakage in prompts
- unsafe tool instructions
- prompt injection in retrieved context
Best practices:
- secret scanning in CI
- lint for forbidden patterns
- use allowlisted tools/actions
- sanitize retrieved documents before injection
- keep system prompts separate from user content
A simple CI/CD workflow
Pull request
- Developer edits prompt
- CI runs:
- lint/format checks
- template rendering checks
- prompt eval suite
- safety/injection tests
- Reviewer approves
- Merge to main
Deployment
- Package prompt artifact
- Deploy to staging
- Run smoke tests
- Canary to small traffic slice
- Monitor metrics
- Roll forward or rollback
Practical folder structure
llm-app/
prompts/
support_reply.yaml
summarize.yaml
evals/
support_reply_tests.jsonl
summarization_tests.jsonl
scripts/
render_prompt.py
run_evals.py
.github/workflows/
prompt-ci.yml
Example CI ideas
You can implement checks like:
- “Prompt must not exceed 2,000 tokens”
- “All variables in template are provided”
- “No sensitive phrases like API keys or credentials”
- “Eval score >= 0.85”
- “JSON output parses correctly”
- “Refusal behavior is preserved”
Rule of thumb
If a prompt affects production behavior, manage it like code:
- version it
- test it
- review it
- deploy it gradually
- monitor it continuously
If you want, I can also show:
- a sample GitHub Actions workflow for prompt CI, or
- a prompt testing/eval harness in Python.