-
Notifications
You must be signed in to change notification settings - Fork 571
fix(litellm): fix gen_ai.request.messages to be as expected
#5255
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: constantinius/fix/redact-message-parts-type-blob
Are you sure you want to change the base?
Conversation
…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": |
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.
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.
| return item | ||
|
|
||
| for message in messages: | ||
| content = message.get("content") |
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.
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.
Issues
Closes https://linear.app/getsentry/issue/TET-1635/redact-images-litellm