https://retellai.com/?utm_source=discord&utm_medium=seo logo
What would you recommend for agents to better hand...
# ❓・ai-evy-support
m
@AI Evy What would you recommend for agents to better handle function errors? What kind of response and status code should a function return in case of errors for the LLMs or agent to understand?
a
Thanks for tagging me @Mohammed Musthafa. I'll look through relevant sources and get back to you shortly.
### Answer For custom functions, your endpoint should return a status code between 200-299 to indicate a successful HTTP request. [(1) ]() The response body can be in various formats—string, buffer, JSON object, or blob—and Retell will convert all of these to a string before sending to the LLM for further processing. Handling Errors: The available documentation doesn't explicitly specify a recommended error response format or status code for function failures. However, based on the general behavior: - If your request fails, it will be retried up to 2 times. - The request will timeout after your specified timeout period, or 2 minutes if not specified. - The function result is capped at 15,000 characters to prevent overloading the LLM context window. Recommendations (general approach) : Since the LLM receives the response as a string, you could return a descriptive error message in the response body (even with a 2xx status code) that the LLM can interpret and communicate to the user. For example:
Copy code
json
{
  "success": false,
  "error": "Unable to retrieve appointment availability. Please try again."
}
You can also configure "Speak After Execution" to have the agent respond based on the function result, allowing it to communicate errors naturally to the user. I don't have specific documentation on recommended error status codes beyond the 200-299 success range. Would you like me to provide a general answer based on my knowledge instead?
​ To learn more, see the sources I considered: [[1] Integrate any system with custom function](https://docs.retellai.com/build/single-multi-prompt/custom-function) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.
m
@AI Evy, what do you think about using 5xx or 4xx response codes for errors?
a
Thanks for the follow-up, @Mohammed Musthafa. I'll get back to you soon.
### Answer I don't have explicit documentation on how Retell AI handles 4xx or 5xx HTTP status codes from custom function endpoints. The available sources only specify that your endpoint should return a 200-299 status code for successful requests, and that failed requests are retried up to 2 times. Based on the Discord thread in the sources, when a function has schema issues or errors, the agent may stop responding after the first line, showing errors like "Failed to get response from any LLM provider." [(1) ]() This suggests that non-2xx responses or function failures can disrupt the agent's flow. Without explicit documentation on 4xx/5xx handling, I'd recommend: - Stick with 2xx status codes and include error details in the response body for the LLM to interpret - This approach ensures the response reaches the LLM, which can then communicate the error naturally to the user Would you like a general answer based on my knowledge about HTTP error handling patterns with LLMs?
​ To learn more, see the sources I considered: [[1] When I am calling the agent is not responding](https://discord.com/channels/1186424376300679209/1402701293633667252) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.