Sanitize Responses message content for assistant history and images#7
Sanitize Responses message content for assistant history and images#7Futureppo wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces message content sanitization for OpenAI-compatible responses, specifically converting assistant output_text to input_text and rewriting Anthropic-style image content (both URL and base64 sources) into standard input_image payloads. Feedback on the changes suggests validating that both data and media_type are non-empty when processing base64 image sources to prevent generating invalid data URLs.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| case "base64": | ||
| url = "data:" + String(source, "media_type", "") + ";base64," + String(source, "data", "") |
There was a problem hiding this comment.
When source type is base64, if data or media_type is empty or missing, url will be constructed as an invalid data URL (e.g., "data:;base64,"), which is not empty and thus bypasses the url == "" check. This will result in sending an invalid image payload upstream. We should validate that both data and media_type are non-empty before constructing the data URL.
| case "base64": | |
| url = "data:" + String(source, "media_type", "") + ";base64," + String(source, "data", "") | |
| case "base64": | |
| data := String(source, "data", "") | |
| mediaType := String(source, "media_type", "") | |
| if data == "" || mediaType == "" { | |
| return nil | |
| } | |
| url = "data:" + mediaType + ";base64," + data |
Summary
output_textto upstream-compatibleinput_text.content: nullfield when a message item has nocontentkey.type: imagewithsource) to Responses-compatibleinput_imageparts before forwarding upstream.Testing
Codex Task