Skip to content

Conversation

@constantinius
Copy link
Contributor

Description

Convert messages to common gen_ai.request.messages structure

Issues

Closes https://linear.app/getsentry/issue/TET-1633/redact-images-openai-openai-agents

@linear
Copy link

linear bot commented Dec 17, 2025

@constantinius constantinius changed the title test(integrations): add test for message conversion fix(openai): convert input message format Dec 17, 2025
@constantinius constantinius marked this pull request as ready for review January 8, 2026 08:34
@constantinius constantinius requested a review from a team as a code owner January 8, 2026 08:34
@constantinius constantinius changed the title fix(openai): convert input message format fix(integrations): openai/openai-agents: convert input message format Jan 8, 2026
Base automatically changed from constantinius/fix/redact-message-parts-type-blob to master January 13, 2026 09:56
@github-actions
Copy link
Contributor

github-actions bot commented Jan 13, 2026

Semver Impact of This PR

🟢 Patch (bug fixes)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


New Features ✨

  • feat(asyncio): Add on-demand way to enable AsyncioIntegration by sentrivana in #5288

Bug Fixes 🐛

  • fix(ai): redact message parts content of type blob by constantinius in #5243
  • fix(clickhouse): Guard against module shadowing by alexander-alderman-webb in #5250
  • fix(gql): Revert signature change of patched gql.Client.execute by alexander-alderman-webb in #5289
  • fix(integrations): openai/openai-agents: convert input message format by constantinius in #5248
  • fix(litellm): Guard against module shadowing by alexander-alderman-webb in #5249
  • fix(pure-eval): Guard against module shadowing by alexander-alderman-webb in #5252
  • fix(ray): Guard against module shadowing by alexander-alderman-webb in #5254
  • fix(threading): Handle channels shadowing by sentrivana in #5299
  • fix(typer): Guard against module shadowing by alexander-alderman-webb in #5253

Documentation 📚

  • docs: Update Python versions banner in README by sentrivana in #5287

Internal Changes 🔧

  • chore(gen_ai): add auto-enablement for google genai by shellmayr in #5295
  • ci(release): Switch from action-prepare-release to Craft by BYK in #5290

🤖 This preview updates automatically when you update the PR.

Comment on lines +96 to +97
input_audio = content_part.get("input_audio", {})
audio_format = input_audio.get("format", "")
Copy link

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", "")
Copy link

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.

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