Prompt
Need prompt templates with variables and inheritance
Latest observation
Nov 4, 2026
OpenAI APIWeb search: off
Here are practical prompt template patterns that support variables and inheritance. I’ll show a clean base approach first, then a few concrete formats you can adapt.
1) Simple variable template
Use placeholders like {{variable_name}}.
Template
You are a {{role}}.
Task:
{{task}}
Context:
{{context}}
Constraints:
{{constraints}}
Output format:
{{output_format}}
Example values
{
"role": "helpful support agent",
"task": "Answer the customer's billing question",
"context": "The customer was charged twice this month",
"constraints": "Be polite, concise, and do not mention internal policies",
"output_format": "A short apology + explanation + next steps"
}
2) Base template + inherited child template
Inheritance means a child prompt reuses a parent prompt and adds or overrides sections.
Base template
[ROLE]
You are {{role}}.
[STYLE]
{{style}}
[GENERAL RULES]
{{general_rules}}
Child template
{{parent}}
[DOMAIN]
You are working in {{domain}}.
[TASK]
{{task}}
[OUTPUT REQUIREMENTS]
{{output_requirements}}
How it works
- Parent/base contains reusable defaults.
- Child includes
{{parent}}conceptually, or your system merges fields from parent and child. - Child can override variables from parent if needed.
3) Structured inheritance using YAML
This works well for prompt management systems.
Base prompt
name: base_assistant
variables:
role: assistant
style: clear, concise
tone: professional
template: |
You are a {{role}}.
Style: {{style}}
Tone: {{tone}}
Child prompt
name: customer_support
extends: base_assistant
variables:
role: customer support agent
tone: friendly and empathetic
domain: billing support
template: |
{{parent}}
Domain: {{domain}}
Handle the user's request with care.
Result after merge
You are a customer support agent.
Style: clear, concise
Tone: friendly and empathetic
Domain: billing support
Handle the user's request with care.
4) Hierarchical prompt layers
A common inheritance model:
- System/base
- Role/domain
- Task-specific
- Instance/input data
Example
Layer 1: Base
You are a reliable AI assistant.
Always be accurate, safe, and concise.
Layer 2: Role
You are a legal research assistant.
Prefer citations and mention uncertainty when needed.
Layer 3: Task
Summarize the following case in plain English.
Layer 4: Variables
Case text: {{case_text}}
Audience: {{audience}}
5) Example inheritance with overrides
Parent
Tone: {{tone}}
Format: {{format}}
Do not use jargon.
Child
Tone: {{tone | default("friendly")}}
Format: {{format | default("bullet points")}}
Use examples where helpful.
If your engine supports defaults, you can specify them. If not, handle defaults in code.
6) Recommended variable set
Typical reusable variables:
roletaskaudiencedomaintonestyleconstraintsexamplesinputoutput_formatsuccess_criteria
7) A robust reusable template
You are {{role}}.
Goal:
{{goal}}
Audience:
{{audience}}
Context:
{{context}}
Instructions:
{{instructions}}
Constraints:
{{constraints}}
Examples:
{{examples}}
Output format:
{{output_format}}
Child variant
You are a {{role}} specialized in {{domain}}.
Goal:
{{goal}}
Audience:
{{audience}}
Context:
{{context}}
Additional instructions:
- {{domain_specific_rule_1}}
- {{domain_specific_rule_2}}
Constraints:
{{constraints}}
Output format:
{{output_format}}
8) Inheritance pattern in code terms
If you’re building a prompt system, inheritance often means:
- Parent template fields are loaded first
- Child template fields overwrite matching keys
- Final prompt is rendered from the merged data
Merge logic example
final_vars = {**parent_vars, **child_vars, **runtime_vars}
Priority:
- runtime variables override child
- child overrides parent
- parent provides defaults
9) Best practices
- Keep base prompts generic and reusable
- Put domain/task specifics in children
- Avoid too many nested inheritance levels
- Use clear variable names
- Support defaults for optional values
- Keep output format explicit
If you want, I can also give you:
- a prompt inheritance schema in JSON/YAML,
- a Python implementation for rendering inherited templates, or
- examples for LangChain / Jinja2 / OpenAI prompt management.