Skip to content

Conversation

@constantinius
Copy link
Contributor

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

linear bot commented Dec 17, 2025

…inal messages and handle data URLs correctly
messages = copy.deepcopy(messages)

def _map_item(item: "Dict[str, Any]") -> "Dict[str, Any]":
if item.get("type") == "image_url":
Copy link

Choose a reason for hiding this comment

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

Missing isinstance check causes crash on non-dict items

Low Severity

The _map_item function calls item.get("type") without first verifying that item is a dict. If the content list contains non-dict elements (e.g., strings or None), this raises an AttributeError. The existing redact_blob_message_parts function in sentry_sdk/ai/utils.py follows a defensive pattern with isinstance(item, dict) and item.get("type"), but the new code doesn't match this pattern. While LiteLLM typically follows OpenAI's format where list items are dicts, malformed or unexpected input from any of the 100+ supported providers could crash the callback.

Fix in Cursor Fix in Web

return item

for message in messages:
content = message.get("content")
Copy link

Choose a reason for hiding this comment

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

Missing isinstance check for messages causes potential crash

Low Severity

The loop iterates over messages and calls message.get("content") without checking if message is a dict. If the messages list contains a non-dict element, this raises an AttributeError. The existing similar functions normalize_message_roles and redact_blob_message_parts both include if not isinstance(message, dict): continue checks before calling .get() on messages. The new code doesn't follow this established pattern.

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.

2 participants