-
Notifications
You must be signed in to change notification settings - Fork 4.4k
fix: redact model output from JSON validation errors #4208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ | |
| from pydantic import TypeAdapter, ValidationError | ||
| from typing_extensions import TypeVar | ||
|
|
||
| from .. import _debug | ||
| from ..exceptions import ModelBehaviorError | ||
| from ..tracing import SpanError | ||
| from ._error_tracing import attach_error_to_current_span | ||
|
|
@@ -32,9 +33,16 @@ def validate_json( | |
| data={}, | ||
| ) | ||
| ) | ||
| raise ModelBehaviorError( | ||
| f"Invalid JSON when parsing {json_str} for {type_adapter}; {e}" | ||
| ) from e | ||
| if not _debug.DONT_LOG_MODEL_DATA: | ||
| raise ModelBehaviorError( | ||
| f"Invalid JSON when parsing {json_str} for {type_adapter}; {e}" | ||
| ) from e | ||
|
|
||
| # Only reachable when the model-data policy suppressed the detailed error above. This is | ||
| # raised outside the except block on purpose: chaining it would keep the ValidationError | ||
| # reachable through __cause__ and __context__, and that error embeds the offending model | ||
| # output in its own message. | ||
| raise ModelBehaviorError(f"Invalid JSON when parsing model output for {type_adapter}") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When model-data logging is disabled, this removes the message/cause leak but the redacted AGENTS.md reference: AGENTS.md:L95-L95 Useful? React with 👍 / 👎. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
For a AGENTS.md reference: AGENTS.md:L95-L95 Useful? React with 👍 / 👎. |
||
|
|
||
|
|
||
| def _to_dump_compatible(obj: Any) -> Any: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When this helper is reached from
handoff(),json_stris the handoff tool-call arguments, so an app that enables model diagnostics but keeps tool-data redaction on (DONT_LOG_MODEL_DATA=False,DONT_LOG_TOOL_DATA=True) still gets the raw handoff payload and chained PydanticValidationError. Use a caller-specific or mixed model/tool redaction policy here instead of keying everyvalidate_jsonfailure only off the model flag.AGENTS.md reference: AGENTS.md:L95-L95
Useful? React with 👍 / 👎.