Skip to content

FunctionTool schema missing required fields for Pydantic BaseModel parameters #4777

@gautamvarmadatla

Description

@gautamvarmadatla

Describe the Bug:
When a FunctionTool accepts a Pydantic BaseModel parameter, the generated function declaration schema does not populate the nested model schema’s required field. As a result, the LLM may treat required model fields as optional and omit them when invoking the tool.

When this happens, model_validate(...) fails internally, but the exception is silently caught. The tool is still invoked with the original raw dict instead of the expected model instance. This defers the failure to the tool implementation, where it may later surface as a downstream runtime error.

Steps to Reproduce:

Create a script with following repro and run it

from pydantic import BaseModel
from google.adk.tools.function_tool import FunctionTool

class SearchRequest(BaseModel):
      query: str           # required
      max_results: int     # required
      filter: str = ""     # optional (has default)

def search(request: SearchRequest) -> list:
      """Search for documents."""
      return []

tool = FunctionTool(search)
decl = tool._get_declaration()
inner_schema = decl.parameters.properties["request"]

print("properties:", list(inner_schema.properties.keys()))
print("required:  ", inner_schema.required)

Expected Behavior:
The generated schema for a BaseModel parameter should include a required field listing all model fields that have no default value. This allows the LLM to correctly identify which fields are mandatory and always include them when invoking the tool.

Observed Behavior:
Running the above script produces the following output:

properties: ['query', 'max_results', 'filter']
required:   None

Environment Details:

  • ADK Library Version (pip show google-adk): 1.26.0
  • Desktop OS : Windows
  • Python Version (python -V) : 3.10

How often has this issue occurred?:

  • Always (100%)

Metadata

Metadata

Labels

tools[Component] This issue is related to tools

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions