You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
FunctionTool schema missing required fields for Pydantic BaseModel parameters #4777
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.
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:
@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.
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.
Activity
surajksharma07 commentedon Mar 10, 2026
@gautamvarmadatla Confirmed the root cause — in
_function_parameter_parse_util.pyaround line 392–403, when iterating a Pydantic BaseModel'smodel_fieldsto build the nested schema,schema.requiredis 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_parameterto usefield_info.is_required()and setschema.requiredbefore 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.
gautamvarmadatla commentedon Mar 10, 2026
Hi @surajksharma07 #4778 does fix it. I tested a bunch of examples locally :)
surajksharma07 commentedon Mar 11, 2026
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.
surajksharma07 commentedon Mar 11, 2026
@xuanyang15 Please have a look into it once.
fix: populate `required` for Pydantic `BaseModel` parameters in `Func…
fix: populate `required` for Pydantic `BaseModel` parameters in `Func…
fix: populate `required` for Pydantic `BaseModel` parameters in `Func…