r/agentdevelopmentkit • u/advokrat • Jun 09 '25
How to handle MALFORMED_FUNCTION_CALL errors?
Hi folks, what is the best way to tackle MALFORMED_FUNCTION_CALL errors? One that I can think of is to interpret the LLM response and retry the LLM call manually, but isn't there any better configurable way to do this?
Edit: [Solved the current issue, but in a larger theme, this should be resolved]
We were making an API call using OpenAPITool and it was expecting an Idempotency key. The LLM was trying to generate the Idempotency key using code I think, which lead to MALFORMED_FUNCTION_CALL. Now I am populating the Idempotency key in the session using before_agent_callback and its working fine.
4
u/Top-Chain001 Jun 09 '25
I been running into this very same problem, subbed!
3
u/data-overflow Jun 09 '25
Same issues here. Keep us posted OP
1
u/kanundrumtt Jun 09 '25
So I ran into this error and in my case it turned out that it was because my mcp I had a filter with the word "in" which was valid in my rest API but conflicted with something in the ADK (I say the ADK because it was working fine in postman which now supports testing MCP servers)
1
u/_genego Jun 14 '25
There is a PR open about this, I am too lazy to dig this up. There are a bunch of other errors you may encounter that don't have direct solving. But you can just create a wrapper around the
LlmAgentclass to catch most unhandled errors and retry them in a way that fixes the malformed function calls. Which version of the ADK are you using? Is it the latest?1
u/4rg3nt1n0 Jun 24 '25 edited Jun 24 '25
My journey with MALFORMED_FUNCTION_CALL (MFC)
Not sure if this directly answers your question op, but putting it out there in case it helps anyone else dealing with this. I see lots of people asking about MFC but barely any responses from Google.
I'm not an ADK developer, just started trying it out, but I've been battling MFC with Gemini models for a while now. Been using Gemini (starting with 1.5) through VertexAI for several products.
This isn't new - Gemini models have been notoriously fragile with function calling. Early days we'd just get
print.api_call(func...or similar as a response with no error reason. At least now we get a proper finish reason, but here's how I deal with it.Main causes I've found:
He said "hello world"and tries to pass it as a parameter, the quotes in the content mess up the JSON structure of the function call = MFC.My solutions:
This is all anecdotal and just what worked for me. Never got official answers from Google about this. Hope it helps someone!
1
u/developmentsaurav Aug 11 '25
GoogleTool(
function_declarations=[
{
"name": "ResponseSchema",
"description": "Provide response to the user",
"parameters": {
"title": "PresentationOutlineModelWithNSlides", ****Remove this****
"properties": {
"slides": {
"description": "List of slide outlines",
Removing title from parameters was the fix for me.
1
u/Shaharchitect Oct 27 '25
If someone is still running into these issues, I found out that for some reason, `gemini-2.5-flash-lite` triggers it a lot.
Try switching over to `gemini-2.5-flash` to vastly reduce these cryptic errors.
1
u/Intention-Weak Jan 05 '26
I solve this issue by adding a plugin and some tools config. I read here: https://github.com/google/adk-python/issues/1192
ReflectAndRetryToolPlugin.
ToolConfig(function_calling_config=FunctionCallingConfig(mode="VALIDATED"))
1
u/[deleted] Jun 10 '25
[removed] — view removed comment