What is a prompt template?
A prompt template is a reusable prompt pattern holding fixed instructions, rules and output format, with variable fields such as {question} or {document} filled with real data at run time.
Its relation to a prompt is that of pattern to product: the prompt is the final text sent to the model, while the template produces that text for each request. A chat template is different: it defines the role tags and message format the model saw in training, with the prompt template's content placed inside it.
- Topic
- Prompts, context, reasoning and generation
How a prompt template works
- Fixed sections are written: task description, rules, examples and expected output format.
- Named fields such as {question}, {document} or {region} are left for changing information.
- The application fills these fields with real data for each request and sends the resulting prompt to the model.
- The template goes under version control; changes are tried on a test set and released after approval.
In more detail
Structured message roles and separating instructions from data
Modern applications rarely render a prompt template into one flat string; instead they compile structured message arrays (`system`, `developer`, `user`, `tool`) and attach JSON Schemas for constrained output. Separating untrusted `{document}` variables into `user` or `tool` messages, rather than interpolating them into the `system` prompt, reduces instruction hijacking.
Template engine security and server-side template injection
When template engines like Jinja2 or Python `.format()` are used, unescaped braces (`{`, `}`) inside JSON snippets or user text can break rendering; passing untrusted input as the template string itself creates Server-Side Template Injection (SSTI) vulnerabilities. Sandboxed rendering, strict variable typing and escaping are needed in production.
Token budgets, truncation and cache-friendly ordering
Naive variable substitution can cause long `{document}` inputs to push total tokens past the model's context window or degrade attention on trailing rules. Production templates therefore pair slots with token-budget allocation, truncation rules and static-prefix ordering so KV-cache prefix caching remains effective.
Commonly confused terms
| Term | How it differs |
|---|---|
| System prompt | A system prompt is the specific text setting the assistant's persona, policies and boundaries; a prompt template is the parameterised blueprint that may assemble the system prompt, few-shot examples and user variables into one or more messages. |
| Prompt pattern | A prompt pattern (in the software-design-pattern sense, e.g., Persona or Cognitive Verifier pattern) is an abstract reusable prompting technique, whereas a prompt template is a concrete executable string or message structure with named placeholders. |
Why a prompt template matters for on-premises AI
In-house applications turn prompt templates into assets much like code: who changed what and when is tracked, one template behaves consistently across applications and a faulty change can be rolled back. User data inserted into a template must be clearly separated from instructions; otherwise commands hidden in a document can cause prompt injection. Templates are retested when the model changes, since the same text can behave differently on different models.
An energy distribution company summarises field crews' fault notes with one template filling {region}, {fault_type} and {note}; a new version is tried on a test set of past notes before release.
Common questions
How does a prompt template differ from a system prompt?
A system prompt sets the model's role and general limits. A prompt template is a pattern, possibly including the system prompt, whose variable fields are filled for each request.
Why should prompt templates be versioned?
Even a small wording change can alter output. Versioning lets changes be tracked, tested and rolled back when problems appear.
Related terms
- Prompt
- System prompt
- Chat template
- Prompt management
- Prompt versioning
- Prompt engineering
- Prompt injection
- Prompt chaining
Sources
In the glossary: Glossary, M to Q