Prompt
What should I use for prompt templates and reusable variables?
Latest observation
Nov 4, 2026
OpenAI APIWeb search: off
A good default is:
- Prompt templates: use a structured template format like Jinja2 or mustache-style placeholders (
{{variable}}) - Reusable variables: store them in a central config / context object rather than hardcoding them in prompts
Practical recommendation
If you’re building LLM prompts, I’d suggest:
-
Keep prompts as versioned text files
e.g.summarize.jinja2,support_reply.jinja2 -
Use named variables
You are a helpful assistant. User name: {{user_name}} Goal: {{goal}} Context: {{context}} -
Define shared variables once
- system instructions
- tone
- brand voice
- safety rules
- output format
-
Render at runtime
- Python: Jinja2
- JS/TS: Handlebars, Mustache, or plain string interpolation if simple
Best choices by need
- Simple prompts:
{{variable}}placeholders - More complex logic: Jinja2
- Typed app workflows: combine template files with a schema/typed config
- Multi-step chains: use a prompt framework like LangChain, LlamaIndex, or your own small templating layer
Avoid
- Hardcoding values directly in prompt strings
- Using lots of ad hoc string concatenation
- Mixing business logic with prompt text
My rule of thumb
- Template format: Jinja2
- Reusable variables: centralized config object / constants
- Validation: schema-validate inputs before rendering
If you want, I can recommend a specific setup for Python, Node.js, or a no-framework approach.
Brands