Start studying
Module 7 · Prompt Engineering Module contents
Module 7  ·  Card 14 / 17beginner

Prompt Templates

A prompt template is a reusable prompt with variable slots.

You fill the slots with user input or retrieved data at runtime.

Templates keep behaviour consistent across many calls.

They make prompts testable and version-controllable like code.

Never build a template by naive string concatenation of untrusted input.

Learn in depth ↓
Module 07 · Prompt Engineering · 17 concepts
In depth  /  15 lines

Prompt Templates, in more detail

A template is a prompt with holes in it that are filled at runtime.

The fixed part carries the instructions and the holes carry the data.

That separation is what makes prompting repeatable rather than artisanal.

The same template runs a thousand times, so a small improvement is worth a great deal.

Templates make prompts testable, since you can run a fixed set of inputs through a change.

They belong in version control, because a prompt edit is a behaviour change like any other.

Naming and versioning them lets you roll back when a change quietly makes things worse.

Never build one by pasting untrusted text straight into the instruction area.

That is prompt injection by construction, and it is the same class of bug as SQL injection.

Put user content inside clear delimiters and say that everything within them is data.

Keep the variable parts small, since a template whose holes carry most of the content is not a template.

Watch the token budget, because a template plus retrieved documents can overflow quietly.

Libraries help but the discipline matters more than the tool.

Log the filled prompt in development, as most surprises are visible the moment you read it.

Treat a template as a function, with inputs, a contract and tests.

Want the full technical article? Wikipedia ↗
Test yourself

One question on this card. Every option explains itself once you pick, right or wrong.

Question 1
Why should a template never be built by pasting untrusted input straight into the prompt?
Prompt Engineering

17 concepts in this module, then a graded test with every answer explained.

Study this module →
↑↓ move↵ openesc close