Skip to the page
Tecyfy

Prompting interview question · easy

What is a "prompt template," and how is it used in designing prompts for language models?

The short answerA prompt template is a reusable prompt with fixed text and named placeholders that the application fills with each request's data, such as {customername}, {document} or {question}.

The full answer

A prompt template is a reusable prompt with fixed text and named placeholders that the application fills with each request's data, such as {customer_name}, {document} or {question}. It separates the parts you design and test once from the parts that change every time, the way a parameterised query separates SQL from its values.

Example

System:
You are a support assistant for {company}. Answer only from the help
articles provided. If the answer is not in them, say so and offer to
connect the customer with a person. Reply in {language}.

User:
<help_articles>
{retrieved_articles}
</help_articles>

<customer_message>
{message}
</customer_message>

The application fills the placeholders from its database and search results, then sends the result to the model.

Why use templates

  • Consistency: every request follows the tested structure and instructions.
  • Separation of concerns: product and domain experts can improve wording without changing code; developers handle data.
  • Testing: the template is evaluated against a set of variable values, and every version can be compared with the last.
  • Version control: templates live in files or a prompt registry with versions, so you know which prompt produced which output and can roll back.
  • Reuse: one template serves many products, languages or customers.
  • Cost: a fixed prefix at the start of the template can be cached across requests, lowering cost and latency.

Designing good templates

  • Put stable instructions first and variable content later, which helps caching and keeps the structure readable.
  • Wrap each variable in clear delimiters (XML tags or headings), so the model knows where data starts and ends.
  • Name variables for what they hold.
  • Decide what happens when a variable is empty: leave out the section, or say "no history available", rather than sending a blank tag.
  • Use a real template engine (such as Jinja) or the prompt features of your framework, for loops over examples and conditional sections.

Security Variables often contain text from users or documents. Treat it as untrusted: delimit it, never place it where it reads as instructions, escape characters that would break your delimiters, and limit length. Delimiters reduce prompt injection but don't eliminate it, so the application must still restrict what the model's output can trigger.

Tooling Most model providers and frameworks support templates: system messages with variables in provider consoles, prompt objects in LangChain and LlamaIndex, and prompt management in MLflow and similar tools, often with evaluation built in.

Last updated 16 October 2026