agent is not able to get dynamic variable value in...
# support
v
I have following prompt, and I am email variable correctly, but it is not checking the variable, if it has value or not, it always ask for email, even there is value in variable email [Email Handling] - Only trigger email handling if the user specifically asks for details via email. Step 1: Check for Existing Email Look for an email address in {{email}}. Step 2: If {{email}} exists: Confirm it with the caller: "I have {{email}} on file. Would you like me to send the details there?" If confirmed, trigger sendEmail tool. Step 3: If {{email}} is not found: Politely ask for an email: "I'd be happy to send you the details! What’s the best email to reach you at?" Once provided, trigger sendEmail tool. here is I am passing variable in outbound call api "assistantOverrides": { "variableValues": { "name": "", "email": "" } }
v
Hi there! I see you're having an issue with dynamic variables in your Vapi assistant 👋 Unfortunately, I can't see your full implementation, but I can definitely help with the issue you're describing. Looking at the code you shared, I can see exactly what's happening! In your outbound call API, you're passing an empty string for the email variable:
Copy code
json
"assistantOverrides": {
    "variableValues": {
      "name": "",
      "email": ""    
    }
}
The agent is asking for an email because you're explicitly setting
email
to an empty string (
""
). When your prompt checks for
{{email}}
, it finds an empty value, which is why it's always going to the "If {{email}} is not found" branch of your logic. To fix this, you need to pass an actual email address in the variable. For example:
Copy code
json
"assistantOverrides": {
    "variableValues": {
      "name": "User Name",
      "email": "user@example.com"    
    }
}
According to the [Vapi documentation on dynamic variables](https://docs.vapi.ai/assistants/dynamic-variables), dynamic variables are used to personalize assistant messages and prompts by setting values to templates defined using double curly braces. When you set
email
to an empty string, the system correctly replaces
{{email}}
with that empty string, which then fails your condition check. If you want to conditionally include the email variable only when you have it, you might need to modify your approach. One option is to not include the email key at all in variableValues when you don't have an email to provide. Is there anything else you'd like to know about handling dynamic variables in Vapi? Source: - [Vapi documentation on dynamic variables](https://docs.vapi.ai/assistants/dynamic-variables)
v
@Vapi but can I put any condition if this variable is empty then ask for email to user
s
Hi @Vansh Soni , since you only want the assistant to do anything regarding an email, if the user asks for it: you could just NOT send the variable at first and only if the user is mentioning email trigger a seperate tool like "getEmail" or something. Via the webhook response of that tool (Email is or Email is not) you could condition the assistant to either confirm the received emailadress or if email is not given collect the emailadress from the user. And then trigger the sendEmail tool. If you leave the prompt like this the assistant will always talk about emails because its so prominent in the given task.
k
Hey! To help track down this issue, could you share: - The call ID - When exactly this happened (the timestamp) - What response you expected to get - What response you actually got instead This would really help us figure out what went wrong!