Skip to content

FIX: Reject non-object tool arguments before calling custom functions in OpenAIResponseTarget - #3519

Open
Lanre Shittu (Shizoqua) wants to merge 1 commit into
microsoft:mainfrom
Shizoqua:fix/custom-function-tool-arguments
Open

Lanre Shittu (Shizoqua) wants to merge 1 commit into
microsoft:mainfrom
Shizoqua:fix/custom-function-tool-arguments

Conversation

@Shizoqua

Copy link
Copy Markdown
Contributor

Description

Fixes #3516.

_execute_call_section_async only checked that parsed tool arguments were a JSON object for registered Tools. Functions in custom_functions were called with whatever json.loads returned, so "null", "[1, 2]" or "\"text\"" reached them as None, a list or a string, and a function reading args["x"] crashed the whole send.

The object check now runs before either kind of function is called. Custom functions get the same handling as tools: a malformed_arguments output the model can recover from, or a ValueError when fail_on_missing_function=True. Unregistered names still return function_not_found.

Tests and Documentation

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

  • null, a list and a string are returned as malformed_arguments with invoked=False, and the custom function is never awaited.
  • With fail_on_missing_function=True, the same input raises ValueError and the custom function is never awaited.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good. Custom functions now use the same JSON-object argument check and error result as registered tools. Unknown function handling stays unchanged.

Reviewed with GitHub Copilot.

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 passes non-object tool arguments to custom functions

2 participants