fix: reject non-object function tool input JSON#3166
Merged
seratch merged 1 commit intoopenai:mainfrom May 7, 2026
Merged
Conversation
Mirror the MCP fix in openai#3135 for the function-tool path: when the model emits a JSON array or scalar instead of an object, `**unpack` into the pydantic params model raises a TypeError that is not matched by `_extract_tool_argument_json_error`, so the ModelBehaviorError-based retry path is bypassed. Validate the parsed shape and raise a ModelBehaviorError with a clear message instead.
seratch
approved these changes
May 7, 2026
Member
seratch
left a comment
There was a problem hiding this comment.
LGTM; we can merge once Codex says 👍
Member
|
@codex review now |
Member
|
@codex review |
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
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.
Summary
Mirror the MCP fix in #3135 for the function-tool path. When the model emits a JSON array or scalar (e.g.
[1, 2, 3],"foo",null) instead of an object as tool arguments,**unpackinto the pydantic params model raises a rawTypeError. ThatTypeErroris not matched by_extract_tool_argument_json_error(which only matchesModelBehaviorErrorwhose message starts with"Invalid JSON input for tool"), so thedefault_tool_error_function"please try again with valid JSON" retry path is bypassed and the run fails with a confusing error instead of asking the model to fix its arguments.This validates the parsed JSON shape inside
_parse_function_tool_json_inputand raises a cleanModelBehaviorErrorfor non-object input, matching the MCP precedent. Affects both the standard runtime tool path and the realtime tool path (both reach the same parser).Test plan
test_function_tool_rejects_non_object_json_inputcovering JSON arrays, strings, numbers, null, and bool — each must raiseModelBehaviorErrorwith"expected a JSON object".uv run pytest tests/test_function_tool.py tests/test_run_step_execution.py tests/test_function_tool_decorator.py tests/test_agent_as_tool.py— 191 passed.uv run ruff check src/agents/tool.py tests/test_function_tool.py— All checks passed.Issue number
N/A — found while reviewing function-tool error handling consistency with #3135.
Checks
make lintandmake format