Skip to content

fix: redact tool-argument values from invalid-input errors - #4012

Open
ioleksiuk wants to merge 1 commit into
openai:mainfrom
ioleksiuk:fix/redact-tool-argument-errors
Open

fix: redact tool-argument values from invalid-input errors#4012
ioleksiuk wants to merge 1 commit into
openai:mainfrom
ioleksiuk:fix/redact-tool-argument-errors

Conversation

@ioleksiuk

Copy link
Copy Markdown
Contributor

Summary

With DONT_LOG_TOOL_DATA set, the ModelBehaviorError raised for an invalid function-tool or Codex-tool argument still embedded the raw values. Pydantic's ValidationError string carries input_value=..., and raise ... from e attached the payload-bearing exception as __cause__/__context__, so tool data surfaced in tracebacks and telemetry even though the adjacent log calls at these sites are already gated on DONT_LOG_TOOL_DATA.

This extends the hardening already applied to the sibling _parse_function_tool_json_input to the type-validation path in tool.py and to codex_tool.py: under DONT_LOG_TOOL_DATA, raise a payload-free summary (field location + error type, no values) from outside the except block, so the ValidationError is neither interpolated into the message nor attached as __context__. Full detail and exception chaining are preserved when tool-data logging is enabled, and the redacted error still names the invalid field so the model can self-correct.

Test plan

Ran the full local stack — make format, make lint, make typecheck, make tests — all pass. Added regression tests in tests/test_error_logging_redaction.py and tests/extensions/experiemental/codex/test_codex_tool.py asserting that the raw value is absent (and __cause__/__context__ are None) when redaction is on, present when off, and that the invalid field name still reaches the caller.

Issue number

None (defense-in-depth; completes the redaction already applied to the sibling parser).

Checks

  • I've added new tests, if relevant
  • I've run the verification stack (make format && make lint && make typecheck && make tests)
  • I've confirmed all verification steps pass
  • If using Codex, I've run /review before submitting this PR (N/A)

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fe146f7283

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/agents/tool.py Outdated
@ioleksiuk
ioleksiuk force-pushed the fix/redact-tool-argument-errors branch from fe146f7 to 6f8c1b0 Compare July 30, 2026 03:00

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6f8c1b0f9b

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/agents/tool.py Outdated
@ioleksiuk
ioleksiuk force-pushed the fix/redact-tool-argument-errors branch from 6f8c1b0 to 81283f0 Compare July 30, 2026 03:51

@seratch seratch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the update. The latest revision fixes the demonstrated mapping-key and unknown top-level-key leaks, but this needs one scope reset before merge.

Please remove field/error summarization from redacted mode and emit only the fixed base error message. The repository's redaction contract requires a fixed message without inspecting sensitive exception metadata, and the successive loc special cases show that classifying Pydantic locations is not a stable security boundary. Preserve the current full validation detail and exception chaining when DONT_LOG_TOOL_DATA=False.

Please also apply the same redacted behavior to Agent.as_tool(parameters=...), which still interpolates and chains the complete ValidationError. Add caller-level adversarial tests for function tools, agent-as-tool, and Codex tools asserting that the sentinel is absent and both __cause__ and __context__ are None in redacted mode.

@ioleksiuk
ioleksiuk force-pushed the fix/redact-tool-argument-errors branch from 81283f0 to c55087d Compare July 30, 2026 15:30
@ioleksiuk
ioleksiuk requested a review from seratch July 30, 2026 15:33
@seratch seratch added this to the 0.19.x milestone Jul 30, 2026
@seratch

seratch commented Jul 30, 2026

Copy link
Copy Markdown
Member

Once the codex cloud review says 👍, this can be merged.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c55087d504

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/agents/tool.py Outdated
Comment thread src/agents/tool.py Outdated
When DONT_LOG_TOOL_DATA is set, the ModelBehaviorError raised for an invalid tool
argument still embedded the raw values: pydantic's ValidationError string carries
input_value=..., and `raise ... from e` attached the payload-bearing exception as
__cause__/__context__, so the data surfaced in tracebacks and telemetry even though the
adjacent log calls are already redacted.

Follow the existing _parse_function_tool_json_input hardening: under DONT_LOG_TOOL_DATA,
raise a fixed base message from outside the except block, so the ValidationError is
neither interpolated into the message nor attached as __context__. The redacted path also
avoids copying the exception to an outer local, so it is not retained in the raising
frame where telemetry that captures frame locals could recover it. Full validation detail
and exception chaining are preserved when DONT_LOG_TOOL_DATA is disabled. This covers all
three tool-argument parsing surfaces: function tools (tool.py), agent tools
(Agent.as_tool), and the experimental Codex tool.

Add caller-level regression tests for each surface asserting the raw value is absent and
__cause__/__context__ are None in redacted mode (and that no ValidationError is retained
in the traceback frame locals), and present with chaining when enabled.
@ioleksiuk
ioleksiuk force-pushed the fix/redact-tool-argument-errors branch from c55087d to f988471 Compare July 30, 2026 15:51

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f988471e77

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/agents/tool.py
validation_failed = True

if validation_failed:
raise ModelBehaviorError(base_message)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Clear raw argument locals before redacted raises

When DONT_LOG_TOOL_DATA is true and validation fails after JSON decoding, this redacted raise still happens in _on_invoke_tool_impl while input, ctx.tool_arguments, and json_data remain live in the traceback frame, so traceback-with-locals telemetry can recover the model-supplied arguments even though the message and exception chain are scrubbed. Fresh evidence beyond the prior exception-local comments is the decoded payload/raw-input locals that remain at the redacted raise; clear or avoid carrying those locals before raising the redacted ModelBehaviorError.

AGENTS.md reference: AGENTS.md:L89-L89

Useful? React with 👍 / 👎.

@seratch seratch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let me know once codex reviews say 👍

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