-
Notifications
You must be signed in to change notification settings - Fork 572
fix(integrations): openai/openai-agents: convert input message format #5248
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(integrations): openai/openai-agents: convert input message format #5248
Conversation
…he schema we expect for the `gen_ai.request.messages`
…ntent and update message handling
…nAI message handling
Semver Impact of This PR🟢 Patch (bug fixes) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨
Bug Fixes 🐛
Documentation 📚
Internal Changes 🔧
🤖 This preview updates automatically when you update the PR. |
| input_audio = content_part.get("input_audio", {}) | ||
| audio_format = input_audio.get("format", "") |
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 code assumes input_audio, image_file, and file content parts are dictionaries. If they are not, calling .get() will raise an AttributeError.
Severity: CRITICAL
🔍 Detailed Analysis
The function _transform_openai_agents_content_part lacks defensive type checks for input_audio, image_file, and file content parts. While the image_url part is safely handled with an isinstance(..., dict) check, the other parts directly call .get() on the value returned from content_part.get(...). If the OpenAI API returns a non-dictionary value (e.g., a string) for these keys, the subsequent .get() call will raise an AttributeError, crashing the message processing pipeline. This inconsistency suggests an oversight, as the need for such checks was recognized elsewhere in the same function.
💡 Suggested Fix
Add isinstance checks for input_audio, image_file, and file_data to ensure they are dictionaries before attempting to call .get() on them. This will make their handling consistent with the safe handling of image_url. For example: audio_format = input_audio.get("format", "") if isinstance(input_audio, dict) else "".
🤖 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/integrations/openai_agents/utils.py#L96-L97
Potential issue: The function `_transform_openai_agents_content_part` lacks defensive
type checks for `input_audio`, `image_file`, and `file` content parts. While the
`image_url` part is safely handled with an `isinstance(..., dict)` check, the other
parts directly call `.get()` on the value returned from `content_part.get(...)`. If the
OpenAI API returns a non-dictionary value (e.g., a string) for these keys, the
subsequent `.get()` call will raise an `AttributeError`, crashing the message processing
pipeline. This inconsistency suggests an oversight, as the need for such checks was
recognized elsewhere in the same function.
Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID: 8537545
|
|
||
| if item.get("type") == "image_url": | ||
| image_url = item.get("image_url") or {} | ||
| url = image_url.get("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 type check for image_url causes crash on string input
Medium Severity
The _convert_message_parts function assumes image_url is always a dict, but if it's a non-empty string, calling .get("url", "") on it raises an AttributeError. The equivalent code in openai_agents/utils.py handles this case with isinstance(image_url, dict) check and falls back to str(image_url). Since _set_input_data runs before the actual API call, this crash would prevent the user's OpenAI call from executing entirely.
Description
Convert messages to common
gen_ai.request.messagesstructureIssues
Closes https://linear.app/getsentry/issue/TET-1633/redact-images-openai-openai-agents