Skip to content

fix: redact invalid JSON payload in ModelBehaviorError data#3485

Merged
seratch merged 1 commit into
openai:mainfrom
LeSingh1:fix/function-tool-bad-json-redaction
May 21, 2026
Merged

fix: redact invalid JSON payload in ModelBehaviorError data#3485
seratch merged 1 commit into
openai:mainfrom
LeSingh1:fix/function-tool-bad-json-redaction

Conversation

@LeSingh1
Copy link
Copy Markdown
Contributor

Summary

_parse_function_tool_json_input in src/agents/tool.py raised ModelBehaviorError(f"Invalid JSON input for tool {tool_name}: {input_json}") from exc regardless of OPENAI_AGENTS_DONT_LOG_TOOL_DATA. The same handler in MCPUtil.invoke_mcp_tool was hardened to redact the payload and drop the chained JSONDecodeError (whose .doc attribute 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_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 message and the chained JSONDecodeError so default_tool_error_function can 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 mypy on the touched files

New 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 chained JSONDecodeError is still attached.

Issue number

N/A

Checks

  • I've added new tests (if relevant)
  • I've added/updated the relevant documentation
  • I've run make lint and make format
  • I've made sure tests pass

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.
@seratch seratch changed the title fix: redact bad JSON payload from function tool ModelBehaviorError fix: redact invalid JSON payload in ModelBehaviorError data when OPENAI_AGENTS_DONT_LOG_TOOL_DATA is set May 21, 2026
@seratch seratch added this to the 0.17.x milestone May 21, 2026
@seratch seratch enabled auto-merge (squash) May 21, 2026 23:51
@seratch seratch disabled auto-merge May 21, 2026 23:51
@seratch seratch enabled auto-merge (squash) May 21, 2026 23:51
@seratch seratch disabled auto-merge May 21, 2026 23:52
@seratch seratch enabled auto-merge (squash) May 21, 2026 23:52
@seratch seratch changed the title fix: redact invalid JSON payload in ModelBehaviorError data when OPENAI_AGENTS_DONT_LOG_TOOL_DATA is set fix: redact invalid JSON payload in ModelBehaviorError data May 21, 2026
@seratch seratch merged commit 813a003 into openai:main May 21, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants