Skip to content

Python: fix(core): preserve null arguments in tool function calls#6199

Open
hanhan761 wants to merge 1 commit into
microsoft:mainfrom
hanhan761:fix-5934-null-args-function-calling
Open

Python: fix(core): preserve null arguments in tool function calls#6199
hanhan761 wants to merge 1 commit into
microsoft:mainfrom
hanhan761:fix-5934-null-args-function-calling

Conversation

@hanhan761
Copy link
Copy Markdown

Summary

Remove exclude_none=True from model_dump() calls in FunctionTool.invoke() and _auto_invoke_function() so that null arguments from the LLM are preserved and passed to the tool function.

Previously, calling a tool with a nullable required parameter (e.g. unit: Literal["C", "F"] | None) and passing null would strip the key via model_dump(exclude_none=True), causing _validate_arguments_against_schema to raise TypeError for "Missing required argument".

Issue

Fixes #5934

Verification

  • FunctionTool.invoke(arguments={"location": "Seattle", "unit": None}) now works correctly
  • Normal calls with non-null values continue to work
  • Tests pass

Copilot AI review requested due to automatic review settings May 30, 2026 07:23
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR changes how tool input arguments are serialized after Pydantic validation, by no longer excluding None values when model_dump() is called.

Changes:

  • Remove exclude_none=True from model_dump() when normalizing mapping inputs.
  • Remove exclude_none=True from model_dump() when normalizing BaseModel inputs.
  • Remove exclude_none=True from model_dump() in the auto-invocation path.

parsed_arguments = self.input_model.model_validate(parsed_arguments).model_dump(
exclude_none=True
)
parsed_arguments = self.input_model.model_validate(parsed_arguments).model_dump()
):
raise TypeError(f"Expected {self.input_model.__name__}, got {type(arguments).__name__}")
parsed_arguments = arguments.model_dump(exclude_none=True)
parsed_arguments = arguments.model_dump()
Comment on lines +1493 to 1496
args = tool.input_model.model_validate(parsed_args).model_dump()
else:
args = dict(parsed_args)
args = _validate_arguments_against_schema(
try:
if not cast(bool, getattr(tool, "_schema_supplied", False)) and tool.input_model is not None:
args = tool.input_model.model_validate(parsed_args).model_dump(exclude_none=True)
args = tool.input_model.model_validate(parsed_args).model_dump()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: Auto function calling removes null arguments

3 participants