Back to Blog
Campaigns

Jinja2 Templates: Dynamic Voice AI Messages That Convert

Master Jinja2 templating for voice AI campaigns. Learn variable substitution, filters, conditionals, and best practices for personalized AI phone calls.

Meeran Malik
9 min read

Static scripts don't work for voice AI. When every call sounds the same, contacts tune out. But when your AI assistant addresses someone by name, references their specific situation, and adapts the conversation accordingly—that's when conversions happen.

Burki uses Jinja2 templating to inject dynamic content into your voice AI campaigns. This guide covers everything from basic variable substitution to advanced conditional logic.


Why Templates Matter for Voice AI

Consider two opening lines:

Static: "Hello, this is an automated call about your upcoming appointment."

Dynamic: "Hi Sarah, this is a reminder about your appointment with Dr. Johnson tomorrow at 2 PM."

The second version:

  • Uses the contact's name (personalization)
  • Mentions specific details (relevance)
  • Includes time-sensitive information (urgency)

Templating makes this scalable across thousands of calls.


Jinja2 Basics for Voice AI

Jinja2 is a powerful templating engine used by Python frameworks worldwide. Burki implements it for campaign messages with voice-specific optimizations.

Variable Substitution

The most basic use: inserting contact data into messages.

Hello {{first_name}}, this is {{assistant_name}} calling from {{company}}.

Variables are wrapped in double curly braces {{variable_name}}. During the call, Burki replaces these with actual values.

Available Variables

Contact Fields

  • {{first_name}} - Contact's first name
  • {{last_name}} - Contact's last name
  • {{phone}} - Contact's phone number
  • {{email}} - Contact's email address
  • Any custom field you've defined

System Variables (Auto-Injected)

  • {{assistant_name}} - Name of the AI assistant
  • {{company}} - Your organization name
  • {{current_date}} - Today's date
  • {{current_time}} - Current time

Campaign Variables

  • Any variable set at the campaign level
  • Shared across all contacts in the campaign

Template Types in Campaigns

Burki supports templating in multiple places within a campaign:

Welcome Message

The first thing your AI says when the call connects:

Hi {{first_name}}, this is {{assistant_name}} from {{company}}. 
I'm calling about your {{service_type}} appointment scheduled for {{appointment_date}}.

Agenda (System Prompt Context)

Added to the AI's system prompt to provide context:

You are calling {{first_name}} {{last_name}} regarding their interest in {{product_name}}.
They submitted a form on {{lead_date}} and indicated their budget is {{budget_range}}.
Focus on addressing their stated concern: {{primary_concern}}.

End Call Message

What the AI says before hanging up:

Thank you for your time, {{first_name}}. 
You'll receive a confirmation email at {{email}} shortly. 
Have a great {{day_of_week}}!

SMS Message (for SMS campaigns)

Hi {{first_name}}, thanks for speaking with us! 
As discussed, here's the link to schedule your follow-up: {{booking_link}}

Built-in Filters

Filters transform variable values. Apply them with the pipe character |.

Text Formatting

FilterInputOutput
title"john smith""John Smith"
upper"hello""HELLO"
lower"HELLO""hello"
capitalize"hello world""Hello world"

Example:

Hello {{first_name|title}}, welcome to {{company|upper}}.

Phone Formatting

The phone_format filter converts raw numbers to spoken format:

Your callback number is {{phone|phone_format}}.

Input: +14155551234 Output: "4 1 5, 5 5 5, 1 2 3 4" (spoken naturally by TTS)

Date Formatting

Format dates for natural speech:

Your appointment is on {{appointment_date|date_format}}.

Input: 2026-01-25 Output: "January 25th, 2026"

Default Values

Provide fallbacks for missing data:

Hello {{first_name|default('there')}}, how are you today?

If first_name is empty, the AI says "Hello there" instead of awkward silence.


Conditional Logic

Sometimes you need different messages based on contact data.

Basic If Statements

{% if appointment_type == 'new_patient' %}
Since this is your first visit, please arrive 15 minutes early to complete paperwork.
{% else %}
We look forward to seeing you again.
{% endif %}

Multiple Conditions

{% if lead_score > 80 %}
I'd love to schedule a demo for you this week.
{% elif lead_score > 50 %}
Would you like me to send over some case studies?
{% else %}
Can I answer any questions about our platform?
{% endif %}

Checking for Empty Values

{% if email %}
I'll send a confirmation to {{email}}.
{% else %}
Could you provide an email address for the confirmation?
{% endif %}

Advanced Techniques

Lists and Loops

If a contact has multiple items:

{% for item in items %}
- {{item.name}}: ${{item.price}}
{% endfor %}

Useful for order confirmations or appointment lists.

Nested Variables

Access nested data structures:

Your account manager is {{account.manager.name}} 
and can be reached at {{account.manager.phone|phone_format}}.

Math Operations

Calculate values inline:

Your total with tax is ${{(subtotal * 1.08)|round(2)}}.

String Joining

Combine list items naturally:

The available times are {{times|join(', ')}}.

Input: ["9 AM", "11 AM", "2 PM"] Output: "The available times are 9 AM, 11 AM, 2 PM."


Voice-Specific Best Practices

Spell Out Numbers for Clarity

Phone numbers and IDs should be spelled out:

Your confirmation number is {{confirmation_id|spell_out}}.

Instead of "ABC123" spoken quickly, the AI says "A, B, C, 1, 2, 3."

Use Natural Language for Dates

Avoid: "Your appointment is 2026-01-25 at 14:00." Better: "Your appointment is January 25th at 2 PM."

Your appointment is {{appointment_date|natural_date}} at {{appointment_time|natural_time}}.

Handle Names Gracefully

Some names are difficult for TTS. Provide pronunciation hints when needed:

{% if name_pronunciation %}
Hello {{name_pronunciation}}.
{% else %}
Hello {{first_name}}.
{% endif %}

Keep Templates Conversational

Written text and spoken text are different. Templates should sound natural when read aloud.

Too formal:

Dear {{first_name}} {{last_name}}, we are contacting you regarding...

Natural:

Hi {{first_name}}, I'm calling about...

Error Handling

Graceful Fallbacks

Always provide defaults for critical fields:

Hello {{first_name|default('there')}}, 
this is {{assistant_name|default('your assistant')}} 
calling from {{company|default('our company')}}.

Template Validation

Burki validates templates before campaign launch:

  • Syntax errors are flagged immediately
  • Missing variables trigger warnings
  • Preview mode shows rendered output for sample contacts

What Happens on Error

If a template fails to render for a specific contact:

  1. The fallback value is used (if defined)
  2. If no fallback, the variable is replaced with empty string
  3. The call proceeds—it's better to say "Hello there" than fail the call
  4. Errors are logged for review

Template Preview and Testing

Before launching a campaign, test your templates:

Preview Mode

  1. Select a contact from your list
  2. Click "Preview Template"
  3. See exactly what the AI will say

Test Calls

  1. Enable "Test Mode" on the campaign
  2. Run a single call to yourself
  3. Verify the template sounds natural

Variable Validation

Burki checks that all referenced variables exist:

Template uses: {{first_name}}, {{appointment_date}}, {{doctor_name}}
Contact has: first_name ✓, appointment_date ✓, doctor_name ✗

Warning: 'doctor_name' is missing for 847 contacts

Fix missing data before launch.


Real-World Template Examples

Appointment Reminder

Hi {{first_name}}, this is a reminder from {{company}} about your 
{{appointment_type|default('appointment')}} 
{% if provider_name %}with {{provider_name}} {% endif %}
on {{appointment_date|natural_date}} at {{appointment_time|natural_time}}.

{% if special_instructions %}
Please remember: {{special_instructions}}.
{% endif %}

Press 1 to confirm, 2 to reschedule, or stay on the line to speak with someone.

Lead Follow-Up

Hi {{first_name}}, this is {{assistant_name}} from {{company}}. 
You recently {{lead_source|default('expressed interest in our services')}}.

{% if days_since_inquiry > 7 %}
I wanted to follow up and see if you had any questions.
{% else %}
I'm calling to answer any questions you might have.
{% endif %}

Do you have a few minutes to chat?

Payment Reminder

Hello {{first_name}}, this is a courtesy call from {{company}} 
regarding invoice {{invoice_number}} for ${{amount_due|round(2)}}.

{% if days_overdue > 30 %}
This payment is now {{days_overdue}} days past due.
{% elif days_overdue > 0 %}
This payment was due on {{due_date|natural_date}}.
{% else %}
Payment is due on {{due_date|natural_date}}.
{% endif %}

Would you like to make a payment now or discuss payment options?

Frequently Asked Questions

What happens if a variable is undefined?

If a variable isn't set and no default is provided, it renders as an empty string. The call continues but may sound awkward. Always use |default() for critical fields.

Can I use HTML in templates?

No. Voice AI templates are plain text that gets spoken by TTS. HTML tags would be read literally ("less than div greater than") which sounds terrible.

How do I include literal curly braces?

Use the raw block:

{% raw %}This shows {{literal}} braces{% endraw %}

Are templates case-sensitive?

Yes. {{First_Name}} and {{first_name}} are different variables. Use consistent naming in your contact data.

Can I create reusable template snippets?

Yes. Create template macros for commonly used phrases:

{% macro greeting(name) %}
Hi {{name}}, this is {{assistant_name}} from {{company}}.
{% endmacro %}

{{greeting(first_name)}}

What's the maximum template length?

Templates can be up to 10,000 characters. However, remember that longer templates mean longer AI responses. Keep welcome messages under 30 seconds when spoken.


Start Personalizing Your Campaigns

Dynamic templates transform generic robocalls into personalized conversations. With Jinja2's flexibility and Burki's voice-specific optimizations, every call can feel tailored to the individual.

Ready to create your first templated campaign? Start your free trial with 200 minutes included.


Last updated: January 2026

Ready to try Burki?

Start your 200-minute free trial today. No credit card required.

Start Free Trial

200 free minutes included. No credit card required.

Related Articles