ModelRefs / Prompt Template — AI Glossary

Prompt Template — AI Glossary

A reusable string template with variables that generates complete prompts for specific tasks by substituting runtime values. A prompt template is not a prompt.

Overview

Prompt templates separate prompt logic from data, enabling systematic testing and version control. LangChain, LlamaIndex, and DSPy all provide template abstractions. Templates typically define system instructions, few-shot examples, and placeholders for user input, retrieved context, and tool output. Stored in code or config files for reproducibility.

Reference details

Topicprompting
Also known asprompt scaffold, prompt recipe
Last reviewed2026-06-24

How it works

  1. A template is a string with named slots, and rendering substitutes values into them to produce the exact text sent to the model.
  2. Rendering has to be deterministic for identical inputs, and the usual sources of drift are incidental: an interpolated timestamp, a set or dictionary iterated in unstable order, or few-shot examples sampled rather than fixed.
  3. The substitution boundary is a security boundary: interpolated retrieved text or tool output arrives in the same token stream as the instructions and is indistinguishable from them to the model.
  4. Delimiting those regions and instructing the model to treat their contents as data is the available mitigation, and it is a convention the model was trained to respect rather than an enforcement.
  5. Because the artifact is text, a change is reviewable as a diff — which is the practical reason prompts belong beside code rather than in a database field, where a one-word edit leaves no reviewable trace.
  6. Traces must store the rendered string rather than the template name, because reproducing a failure requires the values that were substituted and the name alone does not carry them.

Example: A template is a version, whether or not you version it

Change one word of a system prompt and two things happen that are easy to miss. Every evaluation result you have recorded now refers to a prompt that no longer exists, so a regression cannot be attributed to the model or the prompt. And every cached prefix is invalidated — prompt caching matches on an exact prefix, so a single character forces full recomputation of the whole shared block. Both are arguments for the same discipline: templates live in version control with an identifier, and the identifier is recorded alongside every eval run and every trace.

Commonly confused with

A prompt template is not a prompt. The template is the versioned artifact with slots; the prompt is what a specific set of values renders to. Debugging almost always needs the rendered prompt — the exact string the model received — which is why traces should store the render, not just the template name.

When to use it

Reach for it when:

  • Any prompt used more than once, so the wording is a reviewable artifact rather than a literal
  • Where retrieved context or tool output is interpolated and injection risk needs a defined boundary
  • A/B testing prompt variants, which requires both to be addressable

Reach for something else when:

  • One-off exploration, where the abstraction slows the loop down
  • Hiding the rendered prompt from traces — the template alone is not enough to reproduce a failure
  • As a substitute for escaping: interpolated user text is still untrusted input

Continue your research

Use these connected ModelRefs sections to compare alternatives, inspect implementation paths, and review the evidence and governance boundaries relevant to Prompt Template — AI Glossary.

Frequently asked questions

What is Prompt Template?

A reusable string template with variables that generates complete prompts for specific tasks by substituting runtime values.

Is Prompt Template the same as prompt scaffold?

Yes — prompt scaffold, prompt recipe are common aliases for Prompt Template.

What concepts are related to Prompt Template?

Closely related concepts include few shot, system message, dspy.