feat(ai): Redact base64 data URLs in image_url content blocks #5953
1 issue
code-review: Found 1 issue (1 high)
High
AttributeError when image_url content is a string instead of dict - `sentry_sdk/ai/utils.py:600`
The _is_image_type_with_blob_content function at line 600 assumes image_url is always a dict by calling .get("url", ""). However, OpenAI's format allows image_url to be a string directly (e.g., {"type": "image_url", "image_url": "https://..."}), as handled in transform_openai_content_part (lines 142-143). When a string is passed, this will raise AttributeError: 'str' object has no attribute 'get', causing a runtime crash during blob redaction.
Also found at:
sentry_sdk/ai/utils.py:659-660
Duration: 1m 57s · Tokens: 699.5k in / 7.3k out · Cost: $1.43 (+extraction: $0.00, +merge: $0.00, +fix_gate: $0.00)
Annotations
Check failure on line 600 in sentry_sdk/ai/utils.py
sentry-warden / warden: code-review
AttributeError when image_url content is a string instead of dict
The `_is_image_type_with_blob_content` function at line 600 assumes `image_url` is always a dict by calling `.get("url", "")`. However, OpenAI's format allows `image_url` to be a string directly (e.g., `{"type": "image_url", "image_url": "https://..."}`), as handled in `transform_openai_content_part` (lines 142-143). When a string is passed, this will raise `AttributeError: 'str' object has no attribute 'get'`, causing a runtime crash during blob redaction.
Check failure on line 660 in sentry_sdk/ai/utils.py
sentry-warden / warden: code-review
[8C7-DQ7] AttributeError when image_url content is a string instead of dict (additional location)
The `_is_image_type_with_blob_content` function at line 600 assumes `image_url` is always a dict by calling `.get("url", "")`. However, OpenAI's format allows `image_url` to be a string directly (e.g., `{"type": "image_url", "image_url": "https://..."}`), as handled in `transform_openai_content_part` (lines 142-143). When a string is passed, this will raise `AttributeError: 'str' object has no attribute 'get'`, causing a runtime crash during blob redaction.