Prompt template

A reusable prompt with named blanks that code fills at runtime, so one tested instruction can handle many inputs consistently.

fill in the blanks promptsame prompt with different datawhere should the prompt actually live in the codeprompt with variablesboilerplate promptstop copy pasting promptspromt templeteone prompt for every customer

See it

Live demo coming soon

What it is

A prompt template is a reusable instruction structure with named slots filled at runtime, such as customer_name, source_text, and output_schema. The stable parts hold the task, constraints, delimiters, and response shape; the variables carry the data that changes from one request to the next.

Reach for one when the same job runs repeatedly or from code. Templates make prompts versionable, testable, and easier to compare in evals, and they keep a stable prefix stable enough for prompt caching. Jinja2 and Handlebars are familiar template engines, but a typed function is often enough for a small application.

Gotcha: variable content is still model input, not trusted code. A pasted document can contain instructions that fight the template, and a missing variable can silently leave a broken prompt if the renderer is lax. Validate every slot, fail on missing values, label untrusted data with clear delimiters, and keep permissions and spend limits outside the prompt.

Ask AI for it

Build a Jinja2 prompt template using StrictUndefined with exactly three variables: task, source_text, and output_schema. Put stable instructions first, wrap source_text in <source> tags, state that text inside those tags is data rather than instruction, and repeat output_schema as the final block. Add a typed render function that rejects empty values and unknown keys, plus unit tests for missing variables, braces inside source text, multiline input, and an attempted prompt injection. Return the template, renderer, tests, and one rendered example.

You might have meant

promptsystem promptfew shot promptingstructured outputprompt caching