LESSON 1 of 6 Intermediate

Templates & Variables

Build reusable prompt templates with placeholders and variables for repeatable tasks.

6 min read β€’ 2 quiz questions

Templates make prompts repeatable and safe. Treat a template like a filling-in-the-blanks sheet you reuse with different inputs.

Template basics (easy):

  • Stable parts: things that usually stay the same (the role, the core instructions).
  • Dynamic parts (variables): the pieces that change for each call (e.g., {product_name}, {length}, {audience}).
  • Document each variable: type (string, number, list) and example values so callers don’t make mistakes.

Tiny example template (copy and reuse):

β€œYou are a product copywriter. Write a {length}-word description for {product_name} for {audience}. Include 3 key features and a 1-line tagline.”

When you fill the template in code, always validate variables (is length a number? is product_name present?). This prevents broken prompts and weird outputs.

Where to store templates:

  • Keep templates in one place (a repo folder or central service) with simple metadata: name, version, owner, and a short description.
  • Add a small example response for each template so reviewers understand expected outputs.

Versioning hints:

  • Use simple version labels (v1 β†’ v2) and a changelog entry describing why a template changed.
  • Run a quick test when you update a template to make sure it doesn’t break downstream users.

Quick Quiz

Test what you just learned. Pick the best answer for each question.

Q1 Why use prompt templates?

Q2 What belongs in a template variable?