fix: redact invalid JSON payload in ModelBehaviorError data#3485
Merged
seratch merged 1 commit intoMay 21, 2026
Conversation
The MCP path in invoke_mcp_tool already respects DONT_LOG_TOOL_DATA when raising for invalid JSON, but _parse_function_tool_json_input in tool.py still embedded the raw input in the raised ModelBehaviorError and kept the JSONDecodeError chained as __cause__/__context__. The chained exception carries the full payload on .doc, so even with the message redacted the input leaked via traceback display, logs, and trace propagation. Mirror the MCP handler: when DONT_LOG_TOOL_DATA is on, raise outside the except block with a payload-free message and no chained exception. When logging is opted in, preserve the existing behavior (full message + chained JSONDecodeError) so default_tool_error_function can still surface the friendly 'parsing tool arguments' output. Add direct redaction/no-redaction tests next to the MCP equivalents and update three existing tests that relied on chain recovery to opt in to payload logging explicitly.
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
_parse_function_tool_json_inputinsrc/agents/tool.pyraisedModelBehaviorError(f"Invalid JSON input for tool {tool_name}: {input_json}") from excregardless ofOPENAI_AGENTS_DONT_LOG_TOOL_DATA. The same handler inMCPUtil.invoke_mcp_toolwas hardened to redact the payload and drop the chainedJSONDecodeError(whose.docattribute carries the raw input), but the function tool path still leaked the input via the exception message,__cause__, and__context__, which then surfaces in traceback display, logs, and trace propagation.This change mirrors the MCP handler: when
DONT_LOG_TOOL_DATAis on, raise outside theexceptblock with a payload-free message and no chained exception. When logging is opted in, preserve the existing message and the chainedJSONDecodeErrorsodefault_tool_error_functioncan still recover the friendly "parsing tool arguments" output.Test plan
uv run pytest tests/test_function_tool.py tests/test_run_step_execution.py tests/test_tracing_errors.py tests/test_tracing_errors_streamed.py tests/mcp/test_mcp_util.py(224 passed)uv run pytest tests/ --ignore=tests/realtime --ignore=tests/voice --ignore=tests/extensions/memory --ignore=tests/models --ignore=tests/extensions/sandbox(3079 passed, 19 skipped)uv run ruff check,uv run ruff format --check,uv run mypyon the touched filesNew tests cover the redaction and non-redaction paths next to the existing MCP equivalents. Three pre-existing tests that asserted the friendly "parsing tool arguments" output now opt in to payload logging via
monkeypatch.setattr(_debug, "DONT_LOG_TOOL_DATA", False), which is the only configuration in which the chainedJSONDecodeErroris still attached.Issue number
N/A
Checks
make lintandmake format