https://retellai.com/?utm_source=discord&utm_medium=seo logo
Subject: Dynamic variables (prompt_1, prompt_2, et...
# ❓・ai-evy-support
u
@AI Evy Subject: Dynamic variables (prompt_1, prompt_2, etc.) are not arriving in the call payload from n8n Hi @AI Evy, I'm struggling with a Multi-State Agent setup and hope you can clarify something. My agent is reading the literal placeholder text (e.g., {{prompt_1}}) instead of the actual question content it's supposed to receive. My Setup: I am using n8n to trigger an outbound call using the Create Call API. I am passing all my dynamic data inside the retell_llm_dynamic_variables object in the JSON payload. This payload includes contact info (like name, email) and 30 separate question variables (prompt_1, prompt_2, prompt_3, ... prompt_30). These prompt_ variables contain long strings of text for an interview. My n8n JSON for this section looks correct, mapping my data to these keys (e.g., "prompt_1": "[data_from_previous_n8n_node]"). My Retell Agent Setup: It's a Multi-State Agent. Each state (Question_1, Question_2, etc.) is configured with a Say: command, like: Say: "This is question number one: {{prompt_1}}" The Core Problem (The Proof): I ran a real test call (Call ID: call_e0efcc... from my screenshot). When I check the Retell Dashboard for that call, I look at the "Data" tab -> "Dynamic Variables" section. This section only shows the simple variables: email, name, and phone_number. The prompt_1, prompt_2, prompt_3, etc., variables are completely missing from the call log. This strongly suggests my n8n expressions might be failing and sending null (which get dropped), but before I spend hours debugging n8n, can you please confirm: Is there any limit to the number of variables (e.g., 30+ variables) that Retell AI accepts in the retell_llm_dynamic_variables object? Is there a character limit for the value of a single variable (since my questions are long) that would cause it to be dropped? This would help me isolate if the problem is my n8n data structure or a limitation on the Retell API side.
a
Thanks for tagging me @uppercutcr. I'll look through relevant sources and get back to you shortly.
​ To learn more, see the sources I considered: [[1] Dynamic Variables](https://docs.retellai.com/build/dynamic-variables) [[2] Create Phone Call](https://docs.retellai.com/api-references/create-phone-call) ​
### Answer Based on the documentation, I can help clarify the dynamic variables behavior in Retell AI. Here are the key points: Dynamic Variables Requirements: All values in
retell_llm_dynamic_variables
must be strings [(1) ]() . Numbers, booleans, or other data types are not supported . This could be causing your variables to be dropped if they're not properly formatted as strings. Variable Handling: When dynamic variables have no assigned value or are improperly formatted, they remain in their raw form with curly braces intact . For example, if
user_name
is not provided, the prompt "Hello {{user_name}}, how can I help you today?" will remain as "Hello {{user_name}}, how can I help you today?" . API Implementation: When using the Create Phone Call API, you set variables in the
retell_llm_dynamic_variables
field like this [(2) ]() :
Copy code
json
{
 "user_name": "John Smith",
 "product_name": "Premium Plan",
 "account_status": "active"
}
Troubleshooting Steps: 1. Verify all your prompt_ variables are being sent as strings in your n8n payload 2. Check that your n8n expressions are actually evaluating and not sending null values 3. Ensure the variable names match exactly between your API call and your agent configuration The documentation doesn't specify limits on the number of variables or character limits per variable. Since your simple variables (email, name, phone_number) are working but the longer prompt_ variables aren't appearing, this suggests the issue is likely in your n8n data structure or string formatting rather than Retell API limitations. I'd recommend first checking your n8n payload to ensure all 30 prompt_ variables are being sent as properly formatted strings.
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.
u
Thank you for your previous guidance. We have identified the primary structural error in our n8n payload based on your feedback: the prompt_ variables were placed outside the required retell_llm_dynamic_variables object. This is why they were missing from the call log. My original, failing code looked like this (see how the prompt_ variables start after the } closing the dynamic variables block): JSON {   "from_number": "+12033553940",   "to_number": "{{ $('Webhook').item.json.body.phone }}",   "override_agent_id": "agent_2ad5ec8a18f1124b4aca615af9",   "agent_id": "agent_2ad5ec8a18f1124b4aca615af9",   "agent_version": "v4",   "retell_llm_dynamic_variables": {     "name": "{{$('Webhook').item.json.body.first_name}}",     "phone_number": "{{$('Webhook').item.json.body.phone}}",     "email": "{{$('Webhook').item.json.body.email}}" // <--- Error: The block closes here! }, "prompt_1":"{{ $json.message.content.result[0].simplified_question }}", "prompt_2":"{{ $json.message.content.result[1].simplified_question }}", // ... up to prompt_24 } Could you please confirm if the following corrected structure is the proper way to embed all 24 prompt_ variables? In this corrected code, all variables are properly nested within the retell_llm_dynamic_variables object. JSON {   "from_number": "+12033553940",   "to_number": "{{ $('Webhook').item.json.body.phone }}",   "override_agent_id": "agent_2ad5ec8a18f1124b4aca615af9",   "agent_id": "agent_2ad5ec8a18f1124b4aca615af9",   "agent_version": "v4",   "retell_llm_dynamic_variables": {     "name": "{{$('Webhook').item.json.body.first_name}}",     "phone_number": "{{$('Webhook').item.json.body.phone}}",     "email": "{{$('Webhook').item.json.body.email}}", // START OF CORRECTED PROMPT VARIABLES "prompt_1":"{{ $json.message.content.result[0].simplified_question }}",
@AI Evy Thank you for your previous guidance. We have identified the primary structural error in our n8n payload based on your feedback: the prompt_ variables were placed outside the required retell_llm_dynamicvariables object. This is why they were missing from the call log. My original, failing code looked like this (see how the prompt variables start after the } closing the dynamic variables block): JSON { "from_number": "+12033553940", "to_number": "{{ $('Webhook').item.json.body.phone }}", "override_agent_id": "agent_2ad5ec8a18f1124b4aca615af9", "agent_id": "agent_2ad5ec8a18f1124b4aca615af9", "agent_version": "v4", "retell_llm_dynamic_variables": { "name": "{{$('Webhook').item.json.body.first_name}}", "phone_number": "{{$('Webhook').item.json.body.phone}}", "email": "{{$('Webhook').item.json.body.email}}" // <--- Error: The block closes here! }, "prompt_1":"{{ $json.message.content.result[0].simplified_question }}", "prompt_2":"{{ $json.message.content.result[1].simplified_question }}", // ... up to prompt24 } Could you please confirm if the following corrected structure is the proper way to embed all 24 prompt variables? In this corrected code, all variables are properly nested within the retell_llm_dynamic_variables object. JSON { "from_number": "+12033553940", "to_number": "{{ $('Webhook').item.json.body.phone }}", "override_agent_id": "agent_2ad5ec8a18f1124b4aca615af9", "agent_id": "agent_2ad5ec8a18f1124b4aca615af9", "agent_version": "v4", "retell_llm_dynamic_variables": { "name": "{{$('Webhook').item.json.body.first_name}}", "phone_number": "{{$('Webhook').item.json.body.phone}}", "email": "{{$('Webhook').item.json.body.email}}", // START OF CORRECTED PROMPT VARIABLES "prompt_1":"{{ $json.message.content.result[0].simplified_question }}",
a
Thanks for the follow-up, @uppercutcr. I'll get back to you soon.
Your corrected approach of placing all 24 prompt variables inside the
retell_llm_dynamic_variables
object is exactly right [(1) ]() [(2) ]() . The documentation confirms that dynamic variables must be passed in the
retell_llm_dynamic_variables
field when using the Create Phone Call API [(2) ]() . A few additional points to ensure success: - All values in
retell_llm_dynamic_variables
must be strings - Variable names are case-sensitive and must match exactly between your API call and agent configuration - The spaces around variable names will be trimmed when evaluating the variable Your corrected structure should now properly pass all 24 prompt variables to your Multi-State Agent, and they should appear in the call log's Dynamic Variables section.
### Answer Yes, your corrected structure is absolutely correct! You've identified the exact issue - all dynamic variables must be nested within the
retell_llm_dynamic_variables
object [(1) ]() [(2) ]() . Your corrected structure is the proper way to format the Create Phone Call API request [(1) ]() . Here's the correct format based on the documentation:
Copy code
javascript
import Retell from 'retell-sdk';
const client = new Retell({
 apiKey: 'YOUR_RETELL_API_KEY',
}) ;
const phoneCallResponse = await client.call.createPhoneCall({
 from_number: '+14157774444',
 to_number: '+12137774445',
}) ;
console.log(phoneCallResponse.agent_id) ;
For the
retell_llm_dynamic_variables
field specifically, the documentation shows this example structure :
Copy code
json
{
 "user_name": "John Smith",
 "product_name": "Premium Plan",
 "account_status": "active"
}
​ To learn more, see the sources I considered: [[1] Create Phone Call](https://docs.retellai.com/api-references/create-phone-call) [[2] Dynamic Variables](https://docs.retellai.com/build/dynamic-variables) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.
Thanks for the follow-up, @uppercutcr. I'll get back to you soon.
u
@AI Evy Hi @AI Evy, I am having persistent issues sending custom dynamic variables via the Create Phone Call API from our automation platform (n8n). While my simple variables (name, email) arrive correctly, my custom variables (e.g., prompt_1, prompt_2, which contain long interview questions) are not being successfully read by the API. My questions are specific to the data format required for the values of these custom variables: Variable Acceptance: I am using custom variable names like prompt_1, prompt_2, etc. Is it officially supported to use any custom variable name (not just name or email) as long as they are nested under retell_llm_dynamic_variables? String Escaping Requirement: The content of my questions often contains special characters (e.g., apostrophes, commas, double quotes, or line breaks). When sending the API payload, is the value of the dynamic variable required to be a valid JSON-escaped string? Example: If the question content is Did you say "yes"?, should the API receive the value as Did you say \"yes\"? to prevent the API call from breaking? Recommended Method: To prevent JSON syntax errors, should we use a method like JSON.stringify() on the data before placing it in the JSON payload? Or is simple double-quoting sufficient?
a
### Answer Based on the documentation, I can address your specific questions about custom dynamic variables: Variable Acceptance: Yes, you can use any custom variable names (like
prompt_1
,
prompt_2
, etc.) in the
retell_llm_dynamic_variables
object [(1) ]() . The documentation shows this is an object for "optional dynamic variables in key value pairs of string that injects into your Response Engine prompt and tool description" . Custom variable names are fully supported as long as they're properly nested within this object. String Requirements: All values in
retell_llm_dynamic_variables
must be strings [(2) ]() . The documentation specifically states that "All values must be strings. Numbers, booleans, or other data types are not supported" . JSON Escaping: For proper JSON formatting, special characters like quotes must be properly escaped. When your content contains
Did you say "yes"?
, it should be escaped as
Did you say \"yes\"?
in the JSON payload to prevent syntax errors [(3) ]() . A Discord user encountered a similar issue with JSON formatting in
retell_llm_dynamic_variables
and received a 400 error stating "must be object" when the JSON wasn't properly formatted . Recommended Method: Using
JSON.stringify()
on your data before placing it in the payload is the recommended approach to handle special characters, quotes, and line breaks automatically. This ensures proper escaping without manual string manipulation. Here's the correct structure from the documentation [(1) ]() :
Copy code
javascript
import Retell from 'retell-sdk';
const client = new Retell({
 apiKey: 'YOUR_RETELL_API_KEY',
}) ;
const phoneCallResponse = await client.call.createPhoneCall({
 from_number: '+14157774444',
 to_number: '+12137774445',
}) ;
console.log(phoneCallResponse.agent_id) ;
Your
retell_llm_dynamic_variables
should look like this example :
Copy code
json
{ "customer_name": "John Doe" }
Make sure all your
prompt_1
,
prompt_2
, etc. variables are properly JSON-escaped strings within the
retell_llm_dynamic_variables
object.
​ To learn more, see the sources I considered: [[1] Create Phone Call](https://docs.retellai.com/api-references/create-phone-call) [[2] Dynamic Variables](https://docs.retellai.com/build/dynamic-variables) [[3] Discord message from @fredg9582 on 2025-01-13](https://discord.com/channels/1186424376300679209/1186462578310910112/1328256759110045722) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.