-
Notifications
You must be signed in to change notification settings - Fork 572
fix(integrations): pydantic-ai: properly format binary input message parts to be conformant with the gen_ai.request.messages structure
#5251
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?
Conversation
…parts to be conformant with the `gen_ai.request.messages` structure
…-report-image-inputs
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. |
| messages_data = truncate_and_annotate_messages( | ||
| normalized_messages, span, scope | ||
| ) |
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 Pydantic AI integration unconditionally redacts binary message content, ignoring the send_default_pii setting and preventing users from seeing this data in traces.
Severity: HIGH
🔍 Detailed Analysis
In the Pydantic AI integration, the function truncate_and_annotate_messages is called to process AI messages. This function unconditionally calls redact_blob_message_parts, which replaces any binary blob content with the string "[Blob substitute]". This redaction occurs regardless of the user's send_default_pii setting. As a result, users who have enabled PII (send_default_pii=True) to view binary content in their traces will find it redacted, which contradicts the intended behavior and the implementation pattern seen in the OpenAI integration, where a should_send_default_pii() check is performed.
💡 Suggested Fix
Wrap the call to truncate_and_annotate_messages within a conditional that checks should_send_default_pii(). This will align the Pydantic AI integration's behavior with the existing OpenAI integration, ensuring binary content is only redacted when PII is disabled.
🤖 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/pydantic_ai/spans/ai_client.py#L145-L147
Potential issue: In the Pydantic AI integration, the function
`truncate_and_annotate_messages` is called to process AI messages. This function
unconditionally calls `redact_blob_message_parts`, which replaces any binary blob
content with the string `"[Blob substitute]"`. This redaction occurs regardless of the
user's `send_default_pii` setting. As a result, users who have enabled PII
(`send_default_pii=True`) to view binary content in their traces will find it redacted,
which contradicts the intended behavior and the implementation pattern seen in the
OpenAI integration, where a `should_send_default_pii()` check is performed.
Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID: 8534615
Issues
Closes https://linear.app/getsentry/issue/TET-1634/redact-images-pydantic-ai