Skip to content

Conversation

@constantinius
Copy link
Contributor

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

@constantinius constantinius requested a review from a team as a code owner December 17, 2025 09:47
@linear
Copy link

linear bot commented Dec 17, 2025

Co-authored-by: Alex Alderman Webb <alexander.webb@sentry.io>
if isinstance(content, list):
for item in content:
if isinstance(item, dict) and item.get("type") == "blob":
item["content"] = BLOB_DATA_SUBSTITUTE
Copy link

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
Copy link

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.

Fix in Cursor Fix in Web

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants