Prompt Engineering for Production LLM Apps: Templates and Versioning
Prompt engineering for production: system prompts, instructions and examples, few-shot prompting, chain of thought, templates, versioning and eval tests.
In a production LLM application, the prompt is code: it decides behaviour, it breaks when changed carelessly, and it needs versioning, review and tests. Prompt engineering for production is less about clever phrasing and more about structure: a clear system prompt, explicit instructions and output format, the right examples, well-delimited context, and a process for changing all of it safely.
Anatomy of a production prompt
- Role and rules: who the assistant is, what it should and shouldn't do, how to handle uncertainty ("if the documents don't contain the answer, say so").
- Output format: exact structure (JSON schema, headings, length), and what to do when a field is unknown. See structured outputs.
- Examples: a few input-output pairs showing tricky cases, kept short and varied.
- Context: retrieved documents and tool results, clearly delimited (for example in tagged sections) and labelled as data, not instructions.
- History: recent turns, summarised or trimmed to fit; see agent memory.
Techniques that reliably help
| Technique | What it is | When to use |
|---|---|---|
| Be specific | State audience, length, tone, constraints and edge cases explicitly | Always; vague prompts give variable output |
| Few-shot examples | Show 2-5 worked examples of input and ideal output | Formatting, classification boundaries, style |
| Step-by-step reasoning | Ask the model to reason before answering, or use a reasoning mode | Multi-step problems, maths, analysis |
| Delimiters and tags | Wrap documents and user input in labelled sections | Any prompt mixing instructions with data |
| Decomposition (prompt chaining) | Split a task into several calls, each simpler | Long or multi-stage tasks; easier to test each step |
| Self-check | A second call verifies or critiques the first output | High-stakes outputs, at extra cost |
| Prefill / response start | Begin the assistant's answer (e.g. with an opening brace) | Forcing a format where supported |
A prompt is not a security boundary. "Never reveal other customers' data" in a system prompt doesn't stop a determined user or an injected document. Enforce permissions in code; see prompt injection.
Templates and versioning
Keep prompts out of string literals scattered across services. Store them as named, versioned templates with typed variables, and record which version produced every response.
prompt: support_answer
version: 14
model: primary-medium-2026-08 # pinned model version
params: { temperature: 0.2, max_tokens: 600 }
variables: [customer_tier, retrieved_docs, history, question]
template: |
You are the support assistant for Acme. Answer only from <docs>.
If the docs don't contain the answer, say you'll connect a human.
Reply in under 150 words. Customer tier: {{customer_tier}}.
<docs>{{retrieved_docs}}</docs>
<history>{{history}}</history>
Question: {{question}}
eval_suite: support_answer_golden_v6 # must pass before releaseA safe change process
- Small wording changes can shift behaviour on cases you didn't look at; only the eval suite catches that. See LLM evaluation.
- Prompts are tuned to a model. Re-run evals when switching or upgrading models.
- Keep a rollback path: the previous version is one config change away. See LLMOps.
Cost and latency of prompts
- Every token in the system prompt and examples is paid on every request. Trim what doesn't change results.
- Put stable content first so prompt caching can reuse it across requests; see LLM caching.
- Long few-shot sections can sometimes be replaced by fine-tuning when volume is high; see fine-tuning vs RAG.
Where it’s used
Versioned templates with grounding rules, tone guidance and escalation instructions.
Short, strict prompts with schemas and examples of edge cases, at temperature near zero.
System prompts describing tools, planning style and stop conditions; see AI agents.
In an interview
- Describe the prompt's sections and the order you assemble them in, and why.
- Treat prompts as versioned artifacts tied to a model version and an eval suite.
- Say that permissions are enforced in code, not in the prompt.
- Mention prompt caching and trimming as cost levers.
Frequently asked questions
What makes a good production prompt?
Clear role and rules, explicit output format, a few well-chosen examples, clearly delimited context, and instructions for uncertainty, stored as a versioned template tied to a model version and tested by an evaluation suite.
Can a system prompt enforce security?
No. Prompts can be overridden by user input or injected content. Permissions and access control must be enforced in code, not in prompt instructions.
Further reading
- Prompt engineering overviewAnthropic documentation
- Chain-of-Thought Prompting Elicits Reasoning in Large Language ModelsWei et al., NeurIPS 2022