https://retellai.com/?utm_source=discord&utm_medium=seo logo
We’re seeing inconsistent behavior around how the ...
# ❓・ai-evy-support
b
@AI Evy We’re seeing inconsistent behavior around how the ghlContactId is being handled across calls — in some calls, it’s correctly a UUID-style string, and in others, it’s replaced with the caller’s first name or even missing entirely. This seems to be tied to how variables are extracted, passed, or retained during the session. We want to avoid situations where the AI incorrectly substitutes static values (like names) into dynamic fields (like contact IDs), which then breaks downstream API calls and tracking. Could you please clarify: How Retell determines which variable value to pass into tools (e.g., ghlContactId)? Does it pull from context, metadata, memory, user input, or fallbacks? What happens if that variable isn't present? Is there a default fallback (like substituting the first name)? Can we control this behavior? Is there a recommended way to validate or lock variable types (e.g., only allow GHL IDs to be UUIDs)? What’s the most robust way to ensure IDs like ghlContactId are correctly assigned and never overwritten by unrelated values? We’re planning to scale this across multiple clinics, and need confidence that the system won’t “leak” values or use the wrong context between calls. Any suggestions to harden this would be appreciated.
a
Thanks for tagging me @byredyre. I'll look through relevant sources and get back to you shortly.
### Answer Based on the available sources, here's how Retell AI handles dynamic variables and what you can do to ensure consistent behavior: ## How Retell Determines Variable Values Retell AI uses dynamic variables with the
{{variable_name}}
syntax that can be injected into prompts, tool configurations, and other agent components. [(1) ]() For outbound calls, you set variables in the
retell_llm_dynamic_variables
field when using the Create Phone Call API, and all values must be strings. Variables can be used in tool configurations including custom function URLs, tool descriptions, and property descriptions. When you call a function or webhook, the metadata is always available in that object. [(2) ](

▾

) ## Default Behavior and Fallbacks When a dynamic variable has no assigned value, it remains in its raw form with the curly braces intact. [(1) ]() For example, if
user_name
is not provided in a prompt like
"Hello {{user_name}}, how can I help you today?"
, it will remain as
"Hello {{user_name}}, how can I help you today?"
. You can configure agent-level default dynamic variables that serve as fallbacks and will only be used when specific variables aren't included in the call request. ## Recommendations for Robust ID Handling To ensure IDs like
ghlContactId
are correctly assigned: 1. Always pass the variable explicitly in the
retell_llm_dynamic_variables
field for outbound calls 2. Set agent-level defaults for critical variables to prevent them from being undefined 3. Check for unset variables in your conversation flow using equations to verify variables are properly set before using them The sources don't explicitly document type validation or locking mechanisms for variable types. However,
since all values in
retell_llm_dynamic_variables
must be strings , you should validate the format (e.g., UUID pattern) in your application logic before passing them to Retell AI. For multi-clinic scaling, ensure each call request includes the correct
ghlContactId
in the initial API call's
retell_llm_dynamic_variables
object, and consider implementing validation in your backend before making the call. **
​ To learn more, see the sources I considered: [[1] Dynamic Variables](https://docs.retellai.com/build/dynamic-variables) [[2] Personalization with Airtable](

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

) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.