Skip to main content
Prompt templating lets you inject runtime context into assistant instructions so responses are personalized, deterministic, and easier to control.
Treat prompt templates like code: define a stable variable contract, review changes, and version updates before release.

Why This Matters

Without templatingWith templating
Generic responsesContext-aware responses
Hard-coded business valuesRuntime values from your app/call context
Prompt duplication across use casesOne reusable prompt with variables

Variable Access Styles

You can access runtime arguments in two equivalent ways:
StyleExampleWhen to prefer
Namespaced{{ args.customer_name }}Best default, explicit and safer
Root-level{{ customer_name }}Short prompts, low risk of key collisions
Use args.* for most custom business fields. It makes prompts easier to maintain as your variable set grows.
If your team has multiple developers editing prompts, enforce a naming convention like args.customer_*, args.order_*, args.billing_*.

General Jinja-Style Guidelines

Rapida prompt rendering uses Pongo2 (Jinja-style syntax).
Use this safe subset for predictable behavior:
PatternExampleUse for
Variable interpolation{{ args.customer_name }}inject runtime values
Conditionals{% if message.language %}...{% endif %}optional sections/fallback flow
Loops{% for m in messages %}...{% endfor %}render repeated structures
Autoescape control{% autoescape off %}...{% endautoescape %}preserve raw output blocks
Supported patterns above are validated by parser tests in pkg/parsers/pongo2_template_parser_test.go.
Keep template logic lightweight. Put business decision logic in instructions and runtime data, not deeply nested template control flow.

Built-in Variables (What + Why)

system.*

VariableWhat it isWhy it is useful
system.current_dateCurrent UTC dateDate-sensitive flows (appointments, policy windows)
system.current_timeCurrent UTC timeTime-gated behavior
system.current_datetimeFull UTC timestampLogging-style prompts or strict audit wording
system.day_of_weekWeekday nameBusiness-hour or weekday-specific logic
system.date_rfc1123RFC1123 timestampInterop with strict date formats
system.date_unixUnix secondsNumeric date comparisons
system.date_unix_msUnix millisecondsHigh-precision timing context

assistant.*

VariableWhat it isWhy it is useful
assistant.nameAssistant display nameConsistent self-introduction
assistant.idAssistant IDTracing/debug references
assistant.languageDefault assistant languageLanguage fallback guidance
assistant.descriptionAssistant descriptionReinforce role/context in-system prompt

conversation.*

VariableWhat it isWhy it is useful
conversation.idConversation IDSupport/debug workflows
conversation.identifierUser/caller identifierPersonalized behavior
conversation.sourceChannel/sourceChannel-specific instructions
conversation.directionInbound/outbound directionDifferent call-opening behavior
conversation.created_dateConversation start timeSLA or timing-aware responses
conversation.updated_dateLast update timeFreshness-sensitive flows
conversation.durationBest-effort elapsed durationEscalation rules after long calls

session.*

VariableWhat it isWhy it is useful
session.modeSession mode when exposedDifferent style for voice vs text sessions

message.*

VariableWhat it isWhy it is useful
message.textLatest user message textGround immediate response
message.languageDetected/current message languageMultilingual behavior and response control

Practical Production Example

You are {{ assistant.name }}, a billing support assistant for {{ args.company_name }}.

Context:
- Customer: {{ args.customer_name }}
- Plan: {{ args.plan_name }}
- Outstanding balance: {{ args.balance_amount }} {{ args.currency }}
- Channel: {{ conversation.source }}
- Current date: {{ system.current_date }}

Behavior:
1. If balance_amount is empty, ask for account verification before billing help.
2. Keep replies under 2 short sentences for voice clarity.
3. If message.language is set, respond in that language.
4. Never invent invoice IDs. If missing, say data is unavailable and ask to verify.

Runtime Argument Example (from your app/backend)

{
  "company_name": "Acme Telecom",
  "customer_name": "Priya",
  "plan_name": "Business Pro",
  "balance_amount": "129.00",
  "currency": "USD"
}
This enables both:
  • {{ args.customer_name }}
  • {{ customer_name }}
Use one canonical style in production prompts (recommended: args.*) even though both styles resolve.

UX Guidelines for Better Prompts

GuidelineWhy
Prefer explicit variable names (customer_name, not name)Reduces ambiguity in long prompts
Group business fields under args.*Easier schema evolution
Add fallback instruction for missing variablesPrevents hallucinated placeholders
Keep voice responses short in instructionsBetter TTS experience
Keep key names stable across versionsAvoid silent prompt regressions

Common Mistakes

MistakeBetter approach
Using many root-level short keysUse args.* namespaced fields
Assuming every field is always presentAdd fallback rules in prompt
Mixing formatting instructions with business logic randomlySeparate into Context and Behavior blocks
Rewriting prompts per customerReuse one template with runtime args
Do not assume every runtime variable is always present. Add explicit fallback behavior in the prompt for missing or empty values.
For voice assistants, add a hard instruction such as: “Keep responses under 2 short sentences unless the user asks for details.”