https://retellai.com/?utm_source=discord&utm_medium=seo logo
Our meta forms come through with the lead's ZIP co...
# ❓・ai-evy-support
a
@AI Evy Our meta forms come through with the lead's ZIP code, and on the phone the AI selects which location is closest based on that ZIP code. Do you know what strategy the Retell AI currently uses?
a
Thanks for tagging me @Alexander. I'll look through relevant sources and get back to you shortly.
### Answer Retell AI doesn't have a built-in "strategy" for automatically selecting the closest location based on ZIP code [(1) ]() . Instead, you need to implement your own logic using dynamic variables and custom tools. Here's the typical approach: 1. Pass the ZIP code as a dynamic variable when creating the call. You can include it in
retell_llm_dynamic_variables
when making outbound calls [(2) ]() or return it from your inbound webhook [(1) ]() . 2. Implement custom logic using one of these methods: - **Custom function/tool**: Create a custom tool that queries your database or API to look up the closest location based on the ZIP code, then returns that information to the agent - **Pre-process before the call**: Query your system before initiating the call, then pass the closest location information as dynamic variables 3. Use the location data in your agent's prompt or for call transfers. For example, if you need to transfer to different locations, you can use a dynamic variable like
{{transfer_number}}
in the Transfer Call tool [(1) ]() [(3) ]() . The dynamic variables you set can be used throughout your agent configuration - in prompts, begin messages, tool descriptions, and transfer destinations [(1) ]() . **
​ 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) [[3] Routing Calls to Dynamic Number](https://discord.com/channels/1186424376300679209/1346575575963144273) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.
a
@AI Evy we do not have any logic currently built in, but it does work most of the time, so what is the method it is actually using?
a
Thanks for the follow-up, @Alexander. I'll get back to you soon.
### Answer Based on the available documentation, there isn't a built-in automatic ZIP code-to-location matching feature in Retell AI that would work "out of the box" without custom logic [(1) ]() . If your agent is successfully selecting locations based on ZIP codes without you having explicitly built custom logic, the behavior is likely coming from the LLM itself making inferences based on your agent's prompt and the dynamic variables you're passing in . When you pass the ZIP code as a dynamic variable (like
{{zip_code}}
) , the LLM can see this information in the conversation context and may be using its general knowledge to make educated guesses about geographic proximity . However, this approach isn't reliable or accurate since: - The LLM doesn't have access to your actual location database - It's making assumptions based on general geographic knowledge - Results may be inconsistent or incorrect For reliable location routing, you should implement explicit logic using either: - A Custom Function that queries your location database with the ZIP code and returns the closest location - Code Tool to perform the ZIP-to-location lookup [(2) ]() - Pre-processing the ZIP code before the call starts and passing the result as a dynamic variable [(1) ]() The fact that it "works most of the time" suggests the LLM is inferring rather than using a deterministic system, which could lead to errors.
​ To learn more, see the sources I considered: [[1] Dynamic Variables](https://docs.retellai.com/build/dynamic-variables) [[2] Code Tool](https://docs.retellai.com/build/single-multi-prompt/code-tool) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.