Skip to content

FunctionTool schema missing required fields for Pydantic BaseModel parameters #4777

Closed

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%)

Activity

  1. added
    tools[Component] This issue is related to tools
    on Mar 10, 2026
  2. added theissue type on Mar 10, 2026
  3. surajksharma07 commented on Mar 10, 2026

    @surajksharma07
    Collaborator

    @gautamvarmadatla Confirmed the root cause — in _function_parameter_parse_util.py around line 392–403, when iterating a Pydantic BaseModel's model_fields to build the nested schema, schema.required is never populated (and field defaults aren't forwarded either), so the LLM sees all fields as optional.

    As a workaround, you can patch _parse_schema_from_parameter to use field_info.is_required() and set schema.required before returning — could you give that a try and let us know if it resolves the issue on your end?

    Your linked PR #4778 looks like the right fix for this; once you've confirmed the workaround holds up, it would be great to get that PR tested thoroughly before pushing it forward.

  4. gautamvarmadatla commented on Mar 10, 2026

    @gautamvarmadatla
    ContributorAuthor

    Hi @surajksharma07 #4778 does fix it. I tested a bunch of examples locally :)

  5. surajksharma07 commented on Mar 11, 2026

    @surajksharma07
    Collaborator

    Thanks for confirming, @gautamvarmadatla
    Great to hear PR #4778 resolves the issue with the required field not being populated for Pydantic BaseModel parameters.

    We'll move forward with reviewing and merging the PR.

    Team is looking more into it.

  6. surajksharma07 commented on Mar 11, 2026

    @surajksharma07
    Collaborator

    @xuanyang15 Please have a look into it once.

  7. added a commit that references this issue on Mar 24, 2026
    c5d809e
  8. added a commit that references this issue on Apr 9, 2026
    923fc9a
  9. added a commit that references this issue on Aug 11, 2026
    11e3e07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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