-
Notifications
You must be signed in to change notification settings - Fork 572
fix(ai): redact message parts content of type blob #5243
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
base: master
Are you sure you want to change the base?
fix(ai): redact message parts content of type blob #5243
Conversation
Co-authored-by: Alex Alderman Webb <[email protected]>
| if isinstance(content, list): | ||
| for item in content: | ||
| if isinstance(item, dict) and item.get("type") == "blob": | ||
| item["content"] = BLOB_DATA_SUBSTITUTE |
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.
Bug: The variable BLOB_DATA_SUBSTITUTE is used in redact_blob_message_parts but is never defined or imported, which will cause a NameError at runtime.
Severity: CRITICAL
🔍 Detailed Analysis
The function redact_blob_message_parts in sentry_sdk/ai/utils.py attempts to assign the value of BLOB_DATA_SUBSTITUTE on line 220. However, this constant is never defined in the codebase or imported into the file. This will result in a NameError whenever the function is called to redact blob content, such as images in AI monitoring messages. This is a guaranteed runtime crash for the feature being implemented. The intended constant was likely SENSITIVE_DATA_SUBSTITUTE, which is correctly imported and used in tests.
💡 Suggested Fix
In sentry_sdk/ai/utils.py on line 220, replace the undefined variable BLOB_DATA_SUBSTITUTE with the correctly imported and defined constant SENSITIVE_DATA_SUBSTITUTE.
🤖 Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location: sentry_sdk/ai/utils.py#L220
Potential issue: The function `redact_blob_message_parts` in `sentry_sdk/ai/utils.py`
attempts to assign the value of `BLOB_DATA_SUBSTITUTE` on line 220. However, this
constant is never defined in the codebase or imported into the file. This will result in
a `NameError` whenever the function is called to redact blob content, such as images in
AI monitoring messages. This is a guaranteed runtime crash for the feature being
implemented. The intended constant was likely `SENSITIVE_DATA_SUBSTITUTE`, which is
correctly imported and used in tests.
Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID: 8491562
| if isinstance(content, list): | ||
| for item in content: | ||
| if isinstance(item, dict) and item.get("type") == "blob": | ||
| item["content"] = BLOB_DATA_SUBSTITUTE |
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.
Undefined variable BLOB_DATA_SUBSTITUTE causes NameError
High Severity
The code uses BLOB_DATA_SUBSTITUTE which is not defined or imported anywhere in the codebase. Line 8 imports SENSITIVE_DATA_SUBSTITUTE from sentry_sdk._types, but line 220 references the non-existent BLOB_DATA_SUBSTITUTE. This will cause a NameError at runtime whenever a message containing blob content is processed. The tests also assert against SENSITIVE_DATA_SUBSTITUTE, showing a mismatch between the code and expected behavior.
Description
Binary content is useless to us, so we remove it from the message parts of type "blob"
Issues
Contributes to https://linear.app/getsentry/issue/TET-1616/redact-images-in-python-sdk-input-messages