Repository navigation
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
Conversation
…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
Author
|
@microsoft-github-policy-service agree |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #3668.
With
fail_on_missing_function=False,_execute_call_section_asyncreturns amalformed_argumentsfunction 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 aFunctionTool's signature (a wrong type, a missing required argument or an unexpected key) were only checked insideFunctionTool.execute_async, and theValidationErrorfailed the whole send.Toolnow has avalidate_argumentsmethod, which_execute_call_section_asynccalls beforeexecute_async. It accepts any arguments by default, since MCP servers report input errors in the tool result, andFunctionToolimplements it with its argument model. When it raises, the dispatcher returns the samemalformed_argumentsoutput withinvoked=False, or re-raises whenfail_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.MessageToolCallScorerkeeps counting these calls as not executed.Tests and Documentation
Added tests in
tests/unit/prompt_target/target/test_tool.py:FunctionTool.validate_argumentsraisesValidationErrorfor a wrong type, a missing required argument and an unexpected key.send_prompt_async, the same three cases reach the model as amalformed_argumentsoutput in the next request. The function is never called, the output is recorded withinvoked=False, and the stored history still validates for replay. Withfail_on_missing_function=Truethe send raisesValidationErrorafter one request.No docs or notebooks changed, so JupyText was not needed.