Repository navigation
Closed
Labels
core[Component] This issue is related to the core interface and implementation[Component] This issue is related to the core interface and implementationneeds review[Status] The PR/issue is awaiting review from the maintainer[Status] The PR/issue is awaiting review from the maintainer
Description
🔴 Required Information
Describe the Bug:
ADK doesn't seem to check and enforce argument types in function calls. I'm very surprised.
Steps to Reproduce:
Code:
from google.adk.agents.llm_agent import Agent
def set_num(num: int) -> dict:
print("DEBUG:", type(num), num)
return {"status": "success"}
root_agent = Agent(
model='gemini-3-flash-preview',
name='root_agent',
instruction="the user is debugging something. do whatever they instruct",
tools=[set_num],
)Test run:
Running agent root_agent, type exit to exit.
[user]: set num to 3.14159. I know it only accept int. but I'd like to see the error.
DEBUG: <class 'int'> 3
DEBUG: <class 'float'> 3.14159
[root_agent]: It appears that the system accepted the value `3.14159` without returning an error, despite the parameter being defined as an integer. This suggests that the value may have been automatically rounded or truncated by the underlying implementation.
[user]: set num to "foobar"
DEBUG: <class 'str'> foobar
[root_agent]: The tool unexpectedly returned `success` even when passed the string `"foobar"`. It seems the parameter type enforcement for `num` is not currently working as expected in the underlying system.
[user]: set num to null.
DEBUG: <class 'NoneType'> None
[root_agent]: The system also returned `success` when `num` was set to `null`. It appears that the tool is accepting various types without validation errors.
Expected Behavior:
ADK enforces that invalid arguments don't go through, as an average LLM also believes:
Observed Behavior:
Invalid arguments that have different types than the function signature requirements are accepted.
Environment Details:
- ADK Library Version (pip show google-adk): 1.25.1
- Desktop OS: Linux
- Python Version (python -V): 3.13.12
Model Information:
- Are you using LiteLLM: No
- Which model is being used: gemini-3-flash-preview
Reacted by Paul Clavier
Metadata
Metadata
Assignees
Labels
core[Component] This issue is related to the core interface and implementation[Component] This issue is related to the core interface and implementationneeds review[Status] The PR/issue is awaiting review from the maintainer[Status] The PR/issue is awaiting review from the maintainer
Activity
xxlest commentedon Feb 25, 2026
The existing
_preprocess_argsinfunction_tool.py(line 100) already handles Pydantic model coercion and explicitly notes "Future extensions could include: Type coercion for other complex types". Adding primitive type coercion (str→int, str→float, str→bool) here would be a natural extension of this pattern.One design question before I start: when coercion fails (e.g.
"abc"→int), should we:Option (a) is safer for backward compatibility; option (b) surfaces bugs earlier. Happy to go with whichever you prefer. The fix would be ~60-80 lines including tests (extending
test_function_tool_pydantic.py).cuihaoleo commentedon Feb 25, 2026
It seems reasonable to me to pass the validation error to the LLM so it has a chance to correct its error. Maybe this can be simply provided as a standard
before_tool_callbackthat the developer can choose to enable.I also tried other frameworks and here is how they handle this:
LangChain
LangChain appeared to pass the validation error to the agent. This seems like what I suggested. The agent have a chance to correct itself and nothing is broken.
OpenAI
It seems I simply cannot trick
openai-agentsto pass invalid args. The following example either passes 0 or doesn't initiate a function call. Not sure but it was probably that the server enforced valid output in token generation.llalitkumarrr commentedon Feb 26, 2026
Hello @cuihaoleo ,
That is an interesting observation, instead of strictly hardcoding the argument types, what do you think about just using
isinstance()to verify them if absolutely required?We already use type hints to guide the LLM. A user explicitly forcing an incorrect argument through a tool seems like a rare edge case. Even if it does happen the tool will either return an error (if function can not be executed) or the argument will be converted (for example, converting the string 'two' to the number 2 -> check
_preprocess_argsas mentioned by @xxlest ).What are your thoughts on this? We would love to hear more from both of you so that this can be improved.
cuihaoleo commentedon Feb 26, 2026
@llalitkumarrr
isinstanceis not going to distinguish container element types, likelist[int]andlist[str].I'm using a simple case to demonstrate the issue. I actually encountered a more subtle case -- my function accepts an enum, which ADK supports (see #3089), and I noticed that the agent occasionally called it with invalid enum values (which ADK acutally pass as strings). I won't call it rare. Real-world function tools may accept a lot of args + complex types and the LLM can confuse.
I'm fine with keeping the default behaviour to avoid breakage. But providing util funcitons to opt in enforcement/validation would be helpful.
Also, I believe that most developers are unaware of this -- even Google's Gemini believes ADK validates the args. The document should make it clear that there is no validation.
fix: validate and coerce function tool argument types (google#4612)
yuvrajangadsingh commentedon Mar 1, 2026
@llalitkumarrr @cuihaoleo opened PR #4664 for this. implements TypeAdapter-based validation for all annotated param types (primitives, enums, Pydantic models, containers). validation errors go back to the LLM so it can self-correct, same approach cuihaoleo suggested in the comments. all 1426 existing tests pass plus 17 new ones for the validation logic.
fix: validate and coerce function tool argument types (google#4612)
fix: validate and coerce function tool argument types (google#4612)
fix: validate and coerce function tool argument types (google#4612)
fix: validate and coerce function tool argument types (google#4612)
fix: validate and coerce function tool argument types (google#4612)
fix: validate and coerce function tool argument types (google#4612)
2 remaining items
fix: validate and coerce function tool argument types (google#4612)
llalitkumarrr commentedon Mar 16, 2026
Hello @wuliang229 ,
Could you please have a look at this?
fix: validate and coerce function tool argument types (google#4612)
fix: validate and coerce function tool argument types (google#4612)
fix: validate and coerce function tool argument types (google#4612)
fix: validate and coerce function tool argument types (google#4612)
fix: validate and coerce function tool argument types (google#4612)
fix: validate and coerce function tool argument types (google#4612)
fix: validate and coerce function tool argument types (google#4612)
fix: validate and coerce function tool argument types (google#4612)
fix: validate and coerce function tool argument types (google#4612)
fix: validate and coerce function tool argument types