Skip to content

FIX: Return a tool error when arguments don't match a FunctionTool's signature - #3669

Open
Roydon Sequeira (roydonsequeira) wants to merge 1 commit into
microsoft:mainfrom
roydonsequeira:fix/function-tool-argument-validation
Open

Roydon Sequeira (roydonsequeira) wants to merge 1 commit into
microsoft:mainfrom
roydonsequeira:fix/function-tool-argument-validation

Conversation

@roydonsequeira

Copy link
Copy Markdown

Description

Fixes #3668.

With fail_on_missing_function=False, _execute_call_section_async returns a malformed_arguments function output for arguments that are not valid JSON or not a JSON object, so the model can correct the call. Arguments that are a JSON object but don't match a FunctionTool's signature (a wrong type, a missing required argument or an unexpected key) were only checked inside FunctionTool.execute_async, and the ValidationError failed the whole send.

Tool now has a validate_arguments method, which _execute_call_section_async calls before execute_async. It accepts any arguments by default, since MCP servers report input errors in the tool result, and FunctionTool implements it with its argument model. When it raises, the dispatcher returns the same malformed_arguments output with invoked=False, or re-raises when fail_on_missing_function=True, which is what that mode already did. Only the validation call is guarded, so an exception raised by the function itself is not reported as an argument error. MessageToolCallScorer keeps counting these calls as not executed.

Tests and Documentation

Added tests in tests/unit/prompt_target/target/test_tool.py:

  • FunctionTool.validate_arguments raises ValidationError for a wrong type, a missing required argument and an unexpected key.
  • Through send_prompt_async, the same three cases reach the model as a malformed_arguments output in the next request. The function is never called, the output is recorded with invoked=False, and the stored history still validates for replay. With fail_on_missing_function=True the send raises ValidationError after one request.

No docs or notebooks changed, so JupyText was not needed.

…signature

OpenAIResponseTarget returns malformed_arguments for tool arguments that are
not valid JSON or not a JSON object, but a JSON object that failed the
FunctionTool's argument model raised ValidationError out of the send.

Tool.validate_arguments now runs before execution. It accepts any arguments
by default, and FunctionTool checks them against its argument model, so the
dispatcher can return malformed_arguments with invoked=False, or re-raise
when fail_on_missing_function=True, without calling the function.

Fixes microsoft#3668
@roydonsequeira

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: OpenAIResponseTarget fails the send when tool arguments don't match a FunctionTool's signature

1 participant