skip to content

Templated Prompting

Keep a prompt's fixed text apart from the values filled in per request: placeholders, typed inputs and a render step. Interviewers check what a stray value can do to the instruction around it.

part ofPrompt engineeringread it →
on this pageshow

questions

5

What is a prompt template, and how does it differ from the rendered prompt a model actually reads?

level: juniorimportance: must knowfreq 40%

answer

  1. fixed text plus named gaps
  2. a function, not yet a prompt
  3. one instance per request
  4. what the model never sees

basics

~20 s

A prompt template is fixed text with named placeholders; filling them with per-request values produces the rendered prompt. The model reads only the rendered prompt, so that text, not the template, is what you inspect and evaluate.

solid answer

~40 s

A **prompt template** is fixed text containing named placeholders, such as `{customer_name}` or `{ticket_body}`. A render step replaces each placeholder with a value from the request and produces the **rendered prompt**, one instance of the template. The Prompt Report (Schulhoff et al., 2024) defines it the same way: a function with one or more variables that becomes a prompt when input is inserted. The distinction matters because the model only ever reads the rendered text. A template that looks fine in review can still render badly for one request, so debugging and evaluation have to look at rendered output. Placeholders beat concatenating strings at each call site for engineering reasons: the fixed text lives in one reviewable place, its inputs are named, and there is one place to check them.

code

plaintext · 17 lines
plaintext
TEMPLATE
Reply in {language}. Apply the refund policy for the {plan_tier} plan.
Customer: {customer_name}
Ticket:
{ticket_body}

RENDERED FOR REQUEST 1
Reply in Spanish. Apply the refund policy for the pro plan.
Customer: Ana
Ticket:
My export has been stuck since Tuesday.

RENDERED FOR REQUEST 2
Reply in German. Apply the refund policy for the free plan.
Customer: Jonas
Ticket:
I was charged twice this month.

go deeper

for a junior

Recall the two objects: fixed text with named placeholders, and the rendered prompt one request produces. Say plainly that the model reads only the rendered one.

for a middle

Walk through a render with real values, then explain why one render path beats concatenating strings at each call site: named inputs, one place to check them, a source you can diff.

for a senior

Bring a failure where the template read fine and one request rendered badly, such as an empty name. Show that you debug and evaluate on rendered text rather than on the source file.

for a principal

Treat the template as the unit of ownership and review, and the rendered text as the unit of evidence. Say what a team loses when prompts are assembled in scattered code nobody can diff.

## The two objects A **prompt** is the input a language model receives for one call. A **prompt template** is the recipe for many such prompts: fixed text with named gaps. The Prompt Report (Schulhoff et al., 2024) calls it a function containing one or more variables that are replaced by some media, usually text, to create a prompt, and it calls that prompt an instance of the template. - **Placeholder**, or variable: a named gap in the fixed text, such as `{plan_tier}`. The brace syntax is only an illustration; renderers differ. - **Value**: what fills the gap on one request. - **Render step**: the code that takes the template and the values and returns text. - **Rendered prompt**: the result, and the only one of these the model reads. ## A worked render Take a support-reply generator that fills `customer_name`, `plan_tier`, `ticket_body` and a reply language on every request. ```plaintext TEMPLATE You write replies for a software product's support team. Reply in {language}. Apply the refund policy for the {plan_tier} plan. Customer: {customer_name} Ticket: {ticket_body} RENDERED PROMPT You write replies for a software product's support team. Reply in Spanish. Apply the refund policy for the pro plan. Customer: Ana Ticket: My export has been stuck since Tuesday. ``` The render itself runs in a short, fixed order: 1. Load the template for this feature. 2. Check the request's values against what the template expects. 3. Substitute each value for its placeholder. 4. Send the resulting text to the model, and keep a record of it. One template therefore produces a different string for nearly every request, and the two objects behave differently: | | Prompt template | Rendered prompt | |---|---|---| | Contains | Fixed text and placeholders | Fixed text and one request's values | | How many | One per revision | One per request | | Read by | Engineers, in review | The model | | Changes when | Someone edits it | Any value changes | | Useful for | Diffing, ownership, review | Debugging one call, evaluation | ## Why not concatenate strings The alternative is joining strings wherever the model is called. That works for a one-line prompt and gets harder as the prompt grows. The usual reasons to prefer a template are: - **One place to read.** The fixed text sits together, so a reviewer sees the prompt as a whole rather than rebuilding it from control flow in several functions. - **Named inputs.** The placeholders are the prompt's input list, so a missing or misspelled input can be detected. - **One render path.** Checks, logging and tests attach to one function instead of every call site. - **A source you can compare.** Two revisions of a template can be diffed line by line. These are engineering reasons, not measured gains in model quality. The model receives text either way, and an identical final string is an identical input however it was built. ## Why the distinction matters A template can read perfectly and still render badly, because the value is what varies. An empty name leaves `Customer:` with nothing after it. A ticket that pastes a log can bring braces into a pipeline that treats them as syntax. Neither fault is visible in the template file. So the habit to state in an interview is short: when a reply looks wrong, read the rendered prompt for that request before you reread the template. The same reasoning applies to evaluation. An eval has to score what the model read, because a hand-written prompt that expresses the template's intent is a string production may never send. ## What a template does not do The split organises the source of a prompt. It does not change what arrives at the model: - **It is not a security boundary.** The rendered prompt is one stream of text, so a value can still carry instructions. Prompt-injection mitigation is a separate subject. - **It does not settle placement.** Where a variable sits matters too, mainly for cache reuse, and that ordering belongs with prompt-caching prefix design. - **It is not a chat template.** The format a tokenizer applies to turn messages into model input is a different object, one layer below, despite the shared word. The term is also broader than any one library's class of the same name. Whatever the tooling, the two questions stay the same: what was the source, and what did the model read?

  • Does moving from string concatenation to a prompt template change what the model produces?
    Not by itself. If both approaches build the identical string, the model receives an identical input, though sampling can still vary the output. Outputs shift when the rendered text shifts, and a migration often changes it by accident through whitespace or a reordered section. So diff the old and new rendered text on real requests before switching.
  • Can a prompt template's variable hold something other than text?
    In the general definition, yes: Schulhoff et al. (2024) say a variable is replaced by some media, usually text. How a non-text value reaches a model depends on the interface, which may carry it separately from the characters of the prompt. Text is the common case, and the one where substitution rules apply directly.
  • How is a prompt template related to a prompt chain?
    A prompt chain uses two or more templates in succession, with the output of the first prompt filling a variable of the next (Schulhoff et al., 2024). Each link is still an ordinary template and render. The difference for the render step is that one value is now model output, which deserves the same checks as any other value.

A mail-merge letter: the form letter with gaps is the template, and each printed letter is the rendered prompt. The recipient only ever reads the printed one, so that is where you look when a letter goes out wrong.

  • The model sees the template and fills in the placeholders itself.
  • A clean-looking prompt template guarantees that every rendered prompt is clean.
  • Evaluating the template text alone shows how production prompts behave.
  • Placeholders protect a prompt from malicious values, unlike string concatenation.
  • A prompt template is the same thing as a tokenizer's chat template.
open as a page

How should a prompt template's render step handle typed inputs, and missing or empty values?

level: middleimportance: should knowfreq 34%

basics

~20 s

Check a prompt's values against a declared contract before filling anything. A missing required value fails loudly with no model call; a legitimately empty optional value drops its whole section, label included, so no dangling line reaches the model.

open as a page

Why log a prompt template's id and version beside the rendered text, and why must an eval render through production code?

level: seniorimportance: should knowfreq 22%

basics

~20 s

A prompt template's id and version group calls by source and let you compare changes; the rendered text shows what the model actually read. An eval must call the production render, or it scores strings production never sends.

open as a page

In a prompt template pipeline, why would a ticket body containing `{plan_tier}` reach the model with the real tier filled in, and how do you fix it?

level: seniorimportance: should knowfreq 27%

basics

~20 s

A customer value was rendered twice: a later pass scanned earlier output as template source. Compose trusted template text first, then fill values once in a single scan, and never hand an untrusted string to a template engine as source.

open as a page

Should three product teams share one prompt template for support replies or keep per-team copies, and who may edit a shared one?

level: principalimportance: nice to knowfreq 15%

basics

~20 s

The choice depends on whether the teams share a task. While they do, share one core with declared team values, a named owner and every team's eval gating edits. Split once team-specific branches dominate it.

open as a page