https://retellai.com/?utm_source=discord&utm_medium=seo logo
how to use dynamic variable for custom function ca...
# ❓・ai-evy-support
a
@AI Evy how to use dynamic variable for custom function calling
a
Thanks for tagging me @ayushsharma5280. I'll look through relevant sources and get back to you shortly.
### Answer To use a dynamic variable for custom function calling in Retell AI: 1. Define your dynamic variables using the {{variable_name}} syntax; for example, {{user_name}} or {{city}} [(1) ]() . 2. In the custom function configuration, you can insert dynamic variables in the function URL, headers, query parameters, or body as needed. These variables will be replaced with their current values at runtime [(2) ]() . 3. When defining parameters for your custom function, use a JSON schema that references your dynamic variables. Example:
Copy code
json
{
  "type": "object",
  "properties": {
    "city": {
      "type": "string",
      "description": "The city of the weather"
    }
  },
  "required": [
    "city"
  ]
}
4. In your agent prompts or flows, set or update the dynamic variables so they are available when the function is called. You can also extract dynamic variables from API responses for use later in the conversation [(1) ]() . 5. Test your setup to ensure the variables are being passed and replaced correctly in the function call [(2) ]() . If you need to use a dynamic variable in a URL, header, or parameter, just use the {{variable_name}} format in the configuration [(2) ]() [(1) ]() .
​ To learn more, see the sources I considered: [[1] Dynamic Variables](https://docs.retellai.com/build/dynamic-variables) [[2] Custom Function](https://docs.retellai.com/build/conversation-flow/custom-function) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.
a
So i want to first get data Store in variable Then use it a different custom function
@AI Evy So i want to first get data Store in variable Then use it a different custom function
a
Thanks for the follow-up, @ayushsharma5280. I'll get back to you soon.
### Answer You can achieve this in Retell AI by following these steps: 1. Use an "Extract Dynamic Variable" tool to capture data from the user's input and store it as a dynamic variable. For example, you can configure the tool to extract a value (like a name, number, or enum) from the user's response and save it under a variable name of your choice [(1) ]() . 2. Once the variable is set, you can reference it in later custom function calls using the {{variable_name}} syntax. This allows you to use the value you previously extracted as an input to another function or tool [(2) ]() . 3. In your agent’s configuration or prompt, explicitly specify when to extract the variable and when to use it. For example, instruct the agent: “When user provides their email, extract it into {{user_email}}. Later, use {{user_email}} in the next function call.” [(1) ]() 4. Dynamic variables can be used in function URLs, headers, query parameters, or request bodies in subsequent custom function calls [(2) ]() . So, extract the data first and store it in a dynamic variable, then reference that variable in your next function/tool call.
​ To learn more, see the sources I considered: [[1] Extract Dynamic Variables](https://docs.retellai.com/build/single-multi-prompt/extract-dv) [[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.
a
@AI Evy How to set whole flow Share everything
a
Thanks for the follow-up, @ayushsharma5280. I'll get back to you soon.
### Answer To set up a full conversation flow in Retell AI: 1. Go to the Dashboard and select a pre-built template or start a new conversation flow agent. Templates help speed up setup for common use cases like customer support or scheduling [(1) ]() , [(2) ]() . 2. Configure global settings for your agent, including default voice, language, and a global prompt (e.g., “You are a helpful customer service agent.”) [(1) ]() , [(2) ]() . 3. Add nodes to structure your conversation. Nodes can be: - Conversation nodes (for dialogue) - Function nodes (for API calls or custom functions) - Logic nodes (for branching) - End nodes (for call termination) . 4. Connect nodes with edges, defining transition conditions for how the conversation should progress (e.g., based on user input or function results) [(1) ]() , [(2) ]() . 5. Use dynamic variables (e.g., {{user_email}}) to store and reuse data between steps and functions [(1) ]() , [(2) ]() . 6. Test your flow thoroughly using the provided tools, simulating user interactions to ensure accuracy and logical flow [(1) ]() . 7. Launch your agent and monitor its performance via real-time dashboards to track engagement and respons
e quality . Example of a minimal conversation flow setup in code:
Copy code
javascript
import Retell from 'retell-sdk';
const client = new Retell({
  apiKey: 'YOUR_RETELL_API_KEY',
}) ;
const conversationFlowResponse = await client.conversationFlow.retrieve('conversation_flow_id') ;
console.log(conversationFlowResponse.conversation_flow_id) ;
[(3) ]() For a full example of the flow structure:
Copy code
json
{
  "global_prompt": "You are a helpful customer service agent.",
  "tools": [
    {
      "type": "custom",
      "name": "get_customer_info",
      "description": "Get customer information from database",
      "tool_id": "tool_001",
      "url": "<https://api.example.com/customer%22,>
      "method": "GET"
    }
  ],
  "start_node_id": "start",
  "nodes": [
    {
      "id": "start",
      "type": "conversation",
      "instruction": {
        "type": "prompt",
        "text": "Greet the customer and ask how you can help them."
      },
      "edges": [
        {
          "id": "edge_1",
          "transition_condition": {
            "type": "prompt",
            "prompt": "Customer wants to book appointment"
          },
          "destination_node_id": "book_appointment"
        }
      ]
    }
  ],
  "conversation_flow_id": "<string>",
  "version": 123
}
, [(4) ]() For more details, see: - [Conversation Flow Overview]() - [Get Conversation Flow]() - [Retell AI’s Advanced Conversation Flow | Retell AI]()
​ To learn more, see the sources I considered: [[1] Retell AI’s Advanced Conversation Flow | Retell AI](https://www.retellai.com/blog/unlocking-complex-interactions-with-retell-ais-conversation-flow) [[2] Conversation Flow Overview](https://docs.retellai.com/build/conversation-flow/overview) [[3] Get Conversation Flow](https://docs.retellai.com/api-references/get-conversation-flow) [[4] Create Conversation Flow](https://docs.retellai.com/api-references/create-conversation-flow) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.
a
@AI Evy if i add dynamic variable {{id}} in pqth param Its not taking and gives error
a
Thanks for the follow-up, @ayushsharma5280. I'll get back to you soon.
​ To learn more, see the sources I considered: [[1] dynamic variables in function query parameters are not parsed](https://discord.com/channels/1186424376300679209/1414306451656151291) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.
### Answer If you add a dynamic variable like {{id}} in a path parameter and it is not being replaced (causing an error) , this behavior has been reported by other users. There is evidence that dynamic variables might not be parsed correctly in function query parameters or path parameters, resulting in the variable appearing as {{id}} in the actual request URL instead of being replaced with its value [(1) ]() . The recommended approach is to ensure that your backend sends each variable as a separate key-value pair (not as a nested object or list) , and to test variable replacement in prompts first. If the prompt node works but the static/function node does not, this suggests a limitation in how dynamic variables are parsed in non-prompt contexts . Currently, there is no documented workaround for dynamic variables not being parsed in path parameters. You may need to restructure your flow or handle variable substitution outside the path parameter if possible .
a
@AI Evy which functions methods i can use dynamic variable and where i cant (in which fields)
a
Thanks for the follow-up, @ayushsharma5280. I'll get back to you soon.
### Answer Dynamic variables in Retell AI can be used in the following places: - Prompts: You can add dynamic variables in agent instructions, opening greetings, and property or tool descriptions using the {{variable_name}} syntax [(1) ]() . - Custom Function Configurations: Dynamic variables can be inserted in function URLs, headers, query parameters, and request bodies [(2) ]() [(1) ]() . - Tool Configurations: This includes custom function URLs and tool descriptions [(1) ]() . - Call Handling: Dynamic variables can be used in voicemail prompts, transfer call numbers, and warm transfer instructions . However, there are limitations: - There is documented evidence that dynamic variables may not be parsed correctly in query parameters or path parameters for function nodes, potentially resulting in variables like {{id}} not being replaced with their actual values [(3) ]() . - All values passed as dynamic variables must be strings—numbers, booleans, or objects are not supported [(1) ]() [(3) ]() . In summary, dynamic variables are supported in prompts, tool configurations, and function node configurations (URL, headers, query/body) , but may not work reliably in path or query parameters for custom functions [(2) ]() [(1) ]() [(3) ]() .
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.
​ To learn more, see the sources I considered: [[1] Dynamic Variables](https://docs.retellai.com/build/dynamic-variables) [[2] Custom Function](https://docs.retellai.com/build/conversation-flow/custom-function) [[3] dynamic variables in function query parameters are not parsed](https://discord.com/channels/1186424376300679209/1414306451656151291) ​
a
@AI Evy tell basis each method on which params Custom Function Configurations: Dynamic variables can be inserted in function URLs, headers, query parameters, and request bodies (2) (1) .
a
Thanks for the follow-up, @ayushsharma5280. I'll get back to you soon.
### Answer Here’s a detailed breakdown for each HTTP method and where you can use dynamic variables in Retell AI custom function configurations, based directly on the documentation: For all HTTP methods (GET, POST, PATCH, PUT, DELETE) : - URL: You can insert dynamic variables using the {{variable_name}} syntax in the endpoint URL. However, there are reports that dynamic variables may not always be parsed correctly in path parameters or query parameters, so substitution may not always work as expected in these locations [(1) ]() [(2) ]() [(3) ]() . - Headers: You can define custom headers and include dynamic variables here [(1) ]() [(2) ]() . - Query Parameters: You can add dynamic variables as query parameters. Again, note that parsing issues have been reported in some cases [(1) ]() [(2) ]() [(3) ]() . For POST, PATCH, and PUT methods only: - Request Body/Parameters: You can define parameters for the custom function using a JSON schema or JSON form, and dynamic variables can be referenced within these fields [(1) ]() [(2) ]() . Summary Table: | Method | URL | Headers | Query Params | Body/Parameters | |----------------|---------------|-------------
​ To learn more, see the sources I considered: [[1] Custom Function](https://docs.retellai.com/build/conversation-flow/custom-function) [[2] Integrate any system with custom function](https://docs.retellai.com/build/single-multi-prompt/custom-function) [[3] dynamic variables in function query parameters are not parsed](https://discord.com/channels/1186424376300679209/1414306451656151291) [[4] How to pass query URL parameters from conversation to GET request](https://discord.com/channels/1186424376300679209/1384523020110008420) [[5] Dynamic Variables](https://docs.retellai.com/build/dynamic-variables) ​
--|----------------|------------------------| | GET | Yes* | Yes | Yes* | No | | POST | Yes* | Yes | Yes* | Yes (JSON schema) | | PATCH | Yes* | Yes | Yes* | Yes (JSON schema) | | PUT | Yes* | Yes | Yes* | Yes (JSON schema) | | DELETE | Yes* | Yes | Yes* | No | \*Dynamic variables in URL and query parameters may not always be parsed correctly; use with caution [(3) ]() [(4) ]() . For all of these, the value of the dynamic variable must be a string [(5) ]() .
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.
a
@AI Evy whats use of dynamic variable in header?
a
Thanks for the follow-up, @ayushsharma5280. I'll get back to you soon.
### Answer Dynamic variables in headers let you personalize or dynamically control the values sent to your custom function endpoint for each call. For example, you can include authentication tokens, user IDs, or any contextual information that your backend needs, and these values can change based on the current conversation or user. Use the {{variable_name}} syntax in the header value, and it will be replaced with the corresponding dynamic variable at runtime [(1) ]() [(2) ]() .
​ To learn more, see the sources I considered: [[1] Custom Function](https://docs.retellai.com/build/conversation-flow/custom-function) [[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.
a
@AI Evy but for header? isnt that for auth etc?
a
Thanks for the follow-up, @ayushsharma5280. I'll get back to you soon.
### Answer Yes, dynamic variables in headers are commonly used for authentication (such as API keys or tokens) , but they can also be used for any contextual or user-specific data your backend requires. For example, you might include a dynamic variable in a header for: - Authorization tokens that change per user or session (e.g.,
Authorization: Bearer {{user_token}}
) - Passing user IDs, organization IDs, or other identifiers (
X-User-ID: {{user_id}}
) - Custom metadata that your backend expects for logging, routing, or personalization The value in the header will be replaced with the current value of the dynamic variable at runtime, so you can flexibly support scenarios beyond just authentication if needed [(1) ]() [(2) ]() [(3) ](

▾

) .
​ To learn more, see the sources I considered: [[1] Custom Function](https://docs.retellai.com/build/conversation-flow/custom-function) [[2] Dynamic Variables](https://docs.retellai.com/build/dynamic-variables) [[3] Part 1: BuildYour First Retell Voice Al Agent That Sells Cars](

https://www.youtube.com/watch?v=p0DusrDjfjA▾

) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.
a
@AI Evy post request body needs description, if i put static 123, it doesnt work
a
Thanks for the follow-up, @ayushsharma5280. I'll get back to you soon.
### Answer When configuring a POST request body for a custom function in Retell AI, you must define parameters using a JSON schema, and each property should include a description. For example, the schema should look like this:
Copy code
json
{
  "type": "object",
  "properties": {
    "example": {
      "type": "string",
      "description": "A description of the example"
    }
  },
  "required": ["example"]
}
If you set a property to a static value like 123, but do not provide a description, or if you do not use the correct JSON schema structure (including "type": "object" at the top level and proper descriptions) , the function will not save or work properly. Make sure every property in your schema has a description string, even for static values [(1) ]() .
​ To learn more, see the sources I considered: [[1] Custom Function](https://docs.retellai.com/build/conversation-flow/custom-function) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.
a
@AI Evy summarise my thread
a
Thanks for the follow-up, @ayushsharma5280. I'll get back to you soon.
schema structure **Header Usage**: Dynamic variables in headers are useful for authentication tokens, user IDs, and contextual data beyond just auth purposes [(1) ]() [(2) ]() The thread revealed some limitations with dynamic variable parsing in certain contexts, particularly path parameters and query strings, which may require workarounds in your implementation.
### Answer ### Thread Summary Your conversation focused on using dynamic variables with custom functions in Retell AI. Here's what was covered: Main Topics: 1. **Dynamic Variable Basics**: You learned to use {{variable_name}} syntax in custom functions for URLs, headers, query parameters, and request bodies [(1) ]() [(2) ]() 2. **Data Flow Pattern**: You wanted to get data first, store it in a variable, then use it in a different custom function - which is achievable using Extract Dynamic Variable tools followed by referencing the stored variables [(2) ]() 3. **Complete Flow Setup**: You requested information on setting up full conversation flows, including nodes, edges, and transitions [(1) ]() [(2) ]() Key Issues Identified: - **Path Parameter Problems**: Dynamic variables like {{id}} in path parameters don't work reliably and cause errors [(3) ]() - **Method-Specific Limitations**: - GET/DELETE: Can use variables in URL, headers, query params (but with parsing issues) - POST/PATCH/PUT: Additionally support request body parameters [(1) ]() [(2) ]() **JSON Schema Requirements**: For POST requests, you discovered that: - Every property needs a description field [(1) ]() - Must include "type": "object" at top level - Static values like "123" still need proper
​ To learn more, see the sources I considered: [[1] Custom Function](https://docs.retellai.com/build/conversation-flow/custom-function) [[2] Integrate any system with custom function](https://docs.retellai.com/build/single-multi-prompt/custom-function) [[3] Can't use dynamic variable with date-time format in GET URL for custom function?](https://discord.com/channels/1186424376300679209/1405204331896246434) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.
a
@AI Evy so since we use api to create agents and llm in retell And we are building dynamic variable flow, custom actions Id love if you can create a perfect flow including what api dto to use, how to set prompt, etc
a
Thanks for the follow-up, @ayushsharma5280. I'll get back to you soon.
### Answer ### Perfect Flow for Dynamic Variables with Custom Actions Here's a complete flow for building agents with dynamic variables and custom actions using Retell AI APIs: ## 1. Create the Retell LLM with Dynamic Variables First, create your LLM with default dynamic variables and structured prompts [(1) ]() :
Copy code
javascript
import Retell from 'retell-sdk';
const client = new Retell({
 apiKey: 'YOUR_RETELL_API_KEY',
}) ;
const llmResponse = await client.llm.create() ;
console.log(llmResponse.llm_id) ;
Configure your LLM with dynamic variables and structured prompts :
Copy code
json
{
 "general_prompt": "You are ...",
 "begin_message": "Hey I am a virtual assistant calling from Retell Hospital.",
 "default_dynamic_variables": {
 "customer_name": "John Doe"
 }
}
## 2. Structure Your Prompt with Sectional Design Use sectional prompts for better organization [(2) ]() :
Copy code
///## Identity

You are a friendly AI assistant for [Company Name].
Your role is to [specific purpose].
You have expertise in [relevant domains].
///## Style Guardrails
Be concise: Keep responses under 2 sentences unless explaining complex topics.
Be conversational: Use natural language, contractions, and acknowledge what the caller says.
Be empathetic: Show understanding for the caller's situation.
///## Response Guidelines
Return dates in spoken form: Say "January fifteenth" not "1/15".
Ask one question at a time: Avoid overwhelming the caller with multiple questions.
Confirm understanding: Paraphrase important information back to the caller.
## 5. System Variables Available Retell provides these automatic system variables [(3) ]() : | Variable | Description | Example | |----------|-------------|---------| |
{{current_time}}
| Current time in America/Los_Angeles | "Thursday, March 28, 2024 at 11:46:04 PM PST" | |
{{user_number}}
| User's phone number |
+12137771234
| |
{{call_id}}
| Current call session id |
call_12345678906eaa0222bd3dd2a6c
| |
{{direction}}
| Call direction |
inbound
or
outbound
| ## 6. Handling Missing Variables When variables aren't provided, they remain as raw text : - Prompt:
"Hello {{user_name}}, how can I help you today?"
- If
user_name
not provided:
"Hello {{user_name}}, how can I help you today?"
- If
user_name
is "John":
"Hello John, how can I help you today?"
## 7. Important Constraints All dynamic variable values must be strings . Numbers, booleans, or other data types are not supported . For outbound calls, you can supply dynamic variables through the Inbound Call Webhook or directly in the Create Phone Call API . This flow ensures proper integration of dynamic variables with custom actions while maintaining the structured approach recommended by Retell AI.
## 3. Dynamic Variables Usage Dynamic variables work in multiple locations [(3) ]() : - **Prompts**: "Hello {{customer_name}}, thanks for calling!" - **Tool configurations**: Custom function URLs, descriptions - **Call handling**: Voicemail prompts, transfer numbers - Webhook URLs Example implementation :
Copy code
"Hello {{user_name}}, I understand you're interested in {{product_name}}. How can I help you today?"
## 4. Making Outbound Calls with Dynamic Variables When creating phone calls, pass dynamic variables in the API request [(4) ]() :
Copy code
javascript
const phoneCallResponse = await client.call.createPhoneCall({
 from_number: '+14157774444',
 to_number: '+12137774445',
}) ;
console.log(phoneCallResponse.agent_id) ;
Include dynamic variables in the request body :
Copy code
json
{
 "retell_llm_dynamic_variables": {
 "customer_name": "John Doe"
 }
}
​ To learn more, see the sources I considered: [[1] Create Retell LLM](https://docs.retellai.com/api-references/create-retell-llm) [[2] Prompt Engineering Guide](https://docs.retellai.com/build/prompt-engineering-guide) [[3] Dynamic Variables](https://docs.retellai.com/build/dynamic-variables) [[4] Create Phone Call](https://docs.retellai.com/api-references/create-phone-call) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.
a
@AI Evy so basically i want prompt of handling variables when created Should i add a section of all with their descriptions and fallbacks
a
Thanks for the follow-up, @ayushsharma5280. I'll get back to you soon.
### Answer Yes, adding a dedicated section in your prompt for handling variables with descriptions and fallbacks is a best practice. Here's how to structure it: ## Recommended Prompt Structure for Dynamic Variables
Copy code
///## Dynamic Variables
Available variables:
- {{customer_name}}: Customer's full name (fallback: "valued customer")
- {{order_id}}: Current order number (fallback: ask for order details)
- {{appointment_date}}: Scheduled appointment date (fallback: check calendar)
- {{department}}: Target department for transfer (fallback: general support)

Variable handling rules:
- If a variable shows as {{variable_name}}, it wasn't provided - use the fallback approach
- Always confirm variable values with the customer before proceeding
- For missing critical variables, politely ask the customer to provide the information
## Default Behavior for Missing Variables When dynamic variables aren't provided, they remain as raw text in the format
{{variable_name}}
[(1) ]() . You can set default values at the agent level, which serve as fallbacks when specific variables aren't included in the call request . ## Best Practices for Variable Handling **In Prompts**: Check for unset variables by instructing the agent to recognize when variables appear as
{{variable_name}}
and handle them appropriately . **Default System Variables**: Retell automatically provides system variables like
{{current_time}}
,
{{current_agent_state}}
, and
{{session_duration}}
that don't require configuration . **Variable Requirements**: All values in
retell_llm_dynamic_variables
must be strings - numbers, booleans, or other data types are not supported . This approach ensures your agent gracefully handles both provided and missing variables while maintaining a natural conversation flow.
​ To learn more, see the sources I considered: [[1] 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.
a
@AI Evy i like the prompt Rewrite little better with variable examples User id Order id First name Last name With fallback as User ID 1 Order ID 123 First name there Last name (i didn’t provide, then what to do)
a
Thanks for the follow-up, @ayushsharma5280. I'll get back to you soon.
### Answer Here's an improved prompt section for handling your specific dynamic variables with fallbacks:
Copy code
///## Dynamic Variables
Available variables and fallback handling:
- {{user_id}}: Customer's unique identifier (fallback: use "1" as default user ID)
- {{order_id}}: Current order reference number (fallback: use "123" as default order ID)  
- {{first_name}}: Customer's first name (fallback: use "there" to address customer)
- {{last_name}}: Customer's last name (fallback: ask "Could you please provide your last name for verification?")

Variable handling rules:
- If a variable appears as {{variable_name}}, it wasn't provided - apply the specified fallback
- For critical missing information like {{last_name}}, politely request it from the customer
- Use fallback values for non-critical variables to maintain conversation flow
- Always confirm important details with the customer before proceeding with actions

Example responses:
- If {{first_name}} is missing: "Hello there, how can I help you today?"
- If {{last_name}} is missing: "Hi {{first_name}}, could you please provide your last name for verification?"
- If {{order_id}} is missing: "I'll help you with order 123, or please provide your specific order number"
This approach follows Retell AI's default behavior where unset variables remain in their raw
{{variable_name}}
format, allowing you to detect and handle them appropriately [(1) ]() . You can also set default values at the agent level using the
default_dynamic_variables
field, which serve as fallbacks when specific variables aren't included in the call request . Remember that all dynamic variable values must be strings - numbers, booleans, or other data types are not supported .
​ To learn more, see the sources I considered: [[1] 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.
a
@AI Evy can i use this prompt for not provided fall backs ///## Dynamic Variables Available variables and fallback handling: {{user_id}}: Customer's unique identifier (fallback: use "1" as user ID){{order_id}}: Current order reference number (fallback: use "123" as order ID) {{first_name}}: Customer's first name (fallback: use "there" as First Name){{last_name}}: Customer's last name (fallback: Not provided)
a
Thanks for the follow-up, @ayushsharma5280. I'll get back to you soon.
### Answer Your prompt structure can work, but I'd recommend a few improvements for better formatting and clarity: ## Improved Version:
Copy code
///## Dynamic Variables
Available variables and fallback handling:
- {{user_id}}: Customer's unique identifier (fallback: use "1" as user ID)
- {{order_id}}: Current order reference number (fallback: use "123" as order ID)  
- {{first_name}}: Customer's first name (fallback: use "there" as First Name)
- {{last_name}}: Customer's last name (fallback: Not provided)
## Key Issues with Your Original Format: 1. **Missing line breaks**: Your variables are all on one line, which makes it harder to read [(1) ]() 2. **Missing bullet points**: Adding dashes or bullets improves readability [(2) ]() 3. **Spacing inconsistency**: Some variables have extra spaces [(3) ]() ## Important Considerations: **Variable Syntax**: Make sure there are no extra spaces in your variable names -
{{user_id}}
works but
{{ user_id }}
doesn't **Default Behavior**: When dynamic variables aren't provided, they remain as raw text like
{{variable_name}}
[(1) ]() . Your fallback instructions help the agent recognize this and respond appropriately **String Values Only**: All dynamic variable values must be strings - numbers, booleans, or other data types are not supported Your approach of defining fallbacks in the prompt is good practice for handling missing variables gracefully while maintaining conversation flow .
​ To learn more, see the sources I considered: [[1] Dynamic Variables](https://docs.retellai.com/build/dynamic-variables) [[2] How to Write Voice Bot Scripts That Engage Users | Retell AI](https://www.retellai.com/blog/how-to-write-voice-bot-prompt) [[3] Issue with Dynamic Variables.](https://discord.com/channels/1186424376300679209/1336469878068219904) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.
a
@AI Evy Variable handling rules: If a variable appears as {{variable_name}}, it wasn't provided - apply the specified fallbackFor critical missing variable, politely request it from the customerUse fallback values for variables if actual not present to maintain conversation flowAlways confirm important details with the customer before proceeding with actions Is this good for handling variable
a
Thanks for the follow-up, @ayushsharma5280. I'll get back to you soon.
### Answer ### Answer Your variable handling rules are excellent and align well with Retell AI's dynamic variable behavior. Here's a refined version with better formatting:
Copy code
///## Variable Handling Rules:
- If a variable appears as {{variable_name}}, it wasn't provided - apply the specified fallback
- For critical missing variables, politely request it from the customer  
- Use fallback values for variables if actual not present to maintain conversation flow
- Always confirm important details with the customer before proceeding with actions
## Why This Approach Works Well: **Default Behavior Recognition**: When dynamic variables aren't provided, they remain as raw text in the
{{variable_name}}
format, which your rules correctly identify [(1) ]() . **Fallback Strategy**: Your approach of using fallbacks for non-critical variables while requesting critical ones maintains natural conversation flow . **Confirmation Protocol**: Always confirming important details before actions is a best practice that prevents errors . ## Additional Considerations: **Nested Variables**: You can also use nested variables like
{{user.name}}
if your data structure supports it . **System Variables**: Remember that Retell provides automatic system variables like
{{current_time}}
and
{{call_id}}
that don't require fallback handling . **String Requirement**: All dynamic variable values must be strings - numbers, booleans, or other data types are not supported . Your rules provide a comprehensive framework for graceful variable handling while maintaining conversational quality.
​ To learn more, see the sources I considered: [[1] 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.
a
@AI Evy Now I’m implementing custom functions which will have dynamic variable in query or so or being extracted from response So id like a great prompt section Of custom function All functions listed on how to handle them, description, body, response, handling etc etc And then in cases of variable, i think ee can use extract dynamic variable function also and then use it for next So that prompt also on how to call etc Complete flow Be the best prompt engineer and share Covering all cases
a
Thanks for the follow-up, @ayushsharma5280. I'll get back to you soon.
### Answer ### Answer Here's a comprehensive prompt section covering custom functions and dynamic variable extraction for complete flow handling: ## Complete Custom Function & Dynamic Variable Prompt Section
Copy code
///## Custom Functions & Dynamic Variable Management

### Available Custom Functions:
1. get_user_details: Retrieves user information based on name and ID
   - Method: POST
   - Parameters: {"name": "string", "user_id": "string"}
   - Response Variables: Extract user_name, user_email, user_status
   - When to call: When user provides their name or ID for lookup

2. check_order_status: Checks current order information  
   - Method: GET
   - Query Parameters: order_id={{order_id}}
   - Response Variables: Extract order_status, delivery_date, tracking_number
   - When to call: When user asks about order status or provides order number

3. extract_user_details: Captures user information from conversation
   - Type: Extract Dynamic Variable Tool
   - Variables: user_name (Text) , phone_number (Text) , preferred_time (Text)
   - When to call: When user states their name and phone number

### Function Execution Flow:
1. EXTRACT FIRST: Use extract_user_details when user provides personal information
2. PROCESS NEXT: Use extracted variables in subsequent custom function calls  
3. CONFIRM ALWAYS: Verify extracted information before proceeding

### Custom Function Handling Rules:
- Call extract_user_details BEFORE calling other functions that need user data
- Use {{variable_name}} syntax in query parameters and headers
- For POST/PATCH/PUT: Include variables in request body parameters
- For GET/DELETE: Use variables in URL, headers, and query parameters only
- Always speak during execution for user-facing actions
- Always speak after execution to continue conversation flow

### Response Variable Extraction:
- Extract key data from API responses using Response Variables section
- Save extracted data as dynamic variables for later use
- Use format: variable_name -> response.path.to.value
- Example: user_email -> data.user.email

### Error Handling:
- If function call fail
Copy code
s, apologize and ask user to try again
- If required variables are missing, use extract_user_details first
- If API returns error, explain the issue and offer alternatives
- Always maintain conversation flow even during errors

### Variable Usage in Functions:
- Headers: Authorization: Bearer {{auth_token}}
- Query Params: ?user_id={{user_id}}&status={{order_status}}
- Request Body: {"customer_name": "{{user_name}}", "phone": "{{phone_number}}"}
- URLs: Avoid path variables like /users/{{user_id}} - use query params instead
## Key Implementation Details: **Extract Dynamic Variables Tool**: Use this to capture user information before calling other functions [(1) ]() . The tool allows you to extract values from user responses and save them as dynamic variables with types like Text, Number, Enum, or Boolean . **Custom Function Configuration**: When configuring custom functions, you can use dynamic variables in headers, query parameters, and request body parameters [(2) ]() [(3) ]() . Header values and query parameter values can be static or include dynamic variables . **Function Call Sequence**: You should call extract_user_details before calling other functions that need user data [(4) ]() . This ensures variables are properly set before being used in subsequent function calls . **Response Variable Handling**: Extract values from API responses and save them as dynamic variables for use later in the conversation [(2) ]() [(3) ]() . For example, you can extract a user's name from the response and reference it later using
{{user_name}}
. **Request Specifications**: Retell sends requests with specific headers including
X-Retell-Signature
for verification, and the request body includes the function name, call object, and arguments . **Variable Parsing Limitations**: Be aware that dynamic variables in path parameters may not parse correctly [(5) ]() . It's recommended to use query parameters instead of path variables for dynamic d
​ To learn more, see the sources I considered: [[1] Extract Dynamic Variables](https://docs.retellai.com/build/single-multi-prompt/extract-dv) [[2] Integrate any system with custom function](https://docs.retellai.com/build/single-multi-prompt/custom-function) [[3] Custom Function](https://docs.retellai.com/build/conversation-flow/custom-function) [[4] I'm having trouble with Custom Functions that need dynamic path variables in GET endpoints](https://discord.com/channels/1186424376300679209/1420898782828040192) [[5] dynamic variables in function query parameters are not parsed](https://discord.com/channels/1186424376300679209/1414306451656151291) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.
ata [(4) ]() . This comprehensive approach ensures proper sequencing of variable extraction and function calls while handling all edge cases and maintaining conversational flow.