fix(google_genai): Redact binary data in inline_data and fix multi-part message extraction#5977
fix(google_genai): Redact binary data in inline_data and fix multi-part message extraction#5977ericapisani wants to merge 1 commit intomasterfrom
Conversation
…rt message extraction Redact binary/byte data that appears in `inline_data`, which fixes a failing `checkBinaryRedaction` assertion in the AI testing framework. Also includes changes for the following: - Properly handling lists of part-like items (merging into single multi-part user message) - Handling bare inline_data dicts that aren't wrapped in Part objects - Always substituting blob data (both bytes and base64 strings) - Moving PIL import to module level with availability flag to reduce all the dynamic imports of the module within the code Fixes PY-2287 and #5965 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Semver Impact of This PR🟢 Patch (bug fixes) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨
Bug Fixes 🐛Anthropic
Other
Internal Changes 🔧
Other
🤖 This preview updates automatically when you update the PR. |
Codecov Results 📊✅ 142 passed | Total: 142 | Pass Rate: 100% | Execution Time: 21.04s All tests are passing successfully. ❌ Patch coverage is 59.02%. Project has 14068 uncovered lines. Files with missing lines (1)
Generated by Codecov Action |
|
bugbot run |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit d197318. Configure here.
| "data": BLOB_DATA_SUBSTITUTE, | ||
| } | ||
| } | ||
| ) |
There was a problem hiding this comment.
Inline data message missing role and content keys
Medium Severity
The elif "inline_data" in contents: branch produces a message dict {"inline_data": {...}} that has no "role" key and uses "inline_data" instead of "content" as the data key. Every other branch in extract_contents_messages returns messages with both "role" and "content" keys. This malformed structure causes downstream functions like redact_blob_message_parts (which checks message.get("content")) and _truncate_single_message_content_if_present (which checks "content" not in message) to silently skip over these messages. This path is reachable when a list like [Content(...), {"inline_data": {...}}] is processed recursively because not all items are part-like.
Reviewed by Cursor Bugbot for commit d197318. Configure here.
| messages.append( | ||
| { | ||
| "role": role or "user", | ||
| "role": role, |
There was a problem hiding this comment.
Role fallback removed for falsy role values
Low Severity
The "role": role or "user" was changed to "role": role in the elif "text" in contents: branch, removing the fallback for explicitly falsy role values (e.g., None or ""). Since role comes from contents.get("role", "user"), a dict with "role": None would produce a message with role=None. The sibling if parts: branch at line 226 still uses role or "user", creating an inconsistency.
Reviewed by Cursor Bugbot for commit d197318. Configure here.


Redact binary/byte data that appears in
inline_data, which fixes a failingcheckBinaryRedactionassertion in the AI testing framework.Also includes changes for the following:
inline_datadicts that aren't wrapped in Part objectsFixes PY-2287 and #5965