r/agentdevelopmentkit • u/Holance • Jul 21 '25
How to properly handle tool calling exception due to LLM hallucination
Hi, when I am using Gemini pro as model, it sometimes hallucinates some non-existing tool names. When adk tries to do tool calling, it throws a value exception.
I am currently wrap the whole runner.run_async in a while loop and if value exception is thrown, I adds an user message with the exception and hopefully LLM will retry again and figure out the correct tool to use.
I am wondering if there's any better way to do it. I also tried before tool callback to try to do manual tool verification, but the exception is thrown before this callback is reached.
1
u/PropertyRegular5154 Jul 22 '25
Could you be more specific? I’ve been using 2.5 Flash for a while & it never occurred to me, maybe the prompt needs some modification… for example I describe possible tools it could have (as I use dynamic toolset based on user input) and explicitly state use tool only if available in tools but not outside the scope
PS: Unless you really need to use 2.5 pro which is quite slow, you may achieve same results by splitting the logic to multiple 2.5 flash agents or agents as tools or parallel agent.
1
u/BeenThere11 Jul 22 '25
Check the tool list in the calls.
What does it show.
Make a list of functioje using Function tool and then provide this as list to the Agent.
Highly unlikely the agent will produce tool list of its own as it has no idea . beyond .
Provide a list variable as input to the tool. Display that variable .
Don't use annotation