Overview
Dynamic variables allow prompt templates to be personalized at runtime using data from multiple sources. Variables use Mustache-style{{variable_name}} syntax and are resolved from a priority-ordered chain of sources before any prompt is rendered.
Variable Syntax
- Variable names are case-sensitive
- Unresolved variables are replaced with an empty string
- Unresolved variables are logged as warnings for debugging
- Nested/escaped braces are handled gracefully
Sources and Precedence
Variables are merged from highest to lowest priority (higher priority overwrites lower for the same key):Passing Variables
- Chat Request
- Conversation Creation
- Direct Link
- Web Widget
Include
variables in the chat request body:- First request (no
conversationId): variables stored asinitial_variablesandvariables - Subsequent requests: new variables merged into
variables(existing keys overwritten)
Sensitive Variables
Sensitive variables are server-set and never returned in any client-facing API response. They are stored encrypted inconversation_variables.sensitive_variables using AES-256-GCM.
Setting via POST Endpoint
Call from your backend before or during the conversation:Setting via Signed Context Token
Generate a signed JWT from your backend:{ "token": "eyJ..." }
- Frontend receives opaque token, passes as
context_tokenin conversation create or chat request - Bot service decodes JWT server-side, extracts variables
- Keys listed in
sensitive_keysare stored encrypted; others stored as regular variables - Token has expiry — validated before use
Resolution Flow
Prompt Rendering Engine
Shared utility inpackages/shared/src/prompt-renderer.ts:
- Pure function, no side effects
- Used by bot service for all prompt types
- Handles nested/escaped braces gracefully
- Returns list of unresolved variables for logging
Per-Message Variable Overrides
Variables can be updated mid-conversation by includingvariables in any chat request:
conversation_variables.variables record, enabling dynamic context updates as the conversation progresses.
Security Considerations
- Never expose sensitive variable keys in client-side code or HTML. Use signed context tokens.
- Prompt injection: Malicious variable values could attempt to override LLM behavior. Variables should be clearly delimited (e.g., wrapped in quotes or XML tags) when inserted into LLM prompts.
- Context token expiry: Always set a reasonable
expires_in(e.g., 3600 seconds). Expired tokens are rejected. - Sensitive variables: Encrypted at rest, never returned in GET responses, only accessible server-side during prompt rendering.
- Query param variables: Only use for non-sensitive data — query params are logged and visible in browser history.

