fix: filter out empty text blocks from user messages for Gemini compatibility #10728
+102
−4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fix for the "Unable to submit request because it must include at least one parts field" error that occurs when using Gemini models via OpenRouter.
Root Cause
User messages containing empty text blocks (
{ type: "text", text: "" }) were being passed through to the API without filtering. Gemini requires non-empty content in the 'parts' field.Solution
Added filtering of empty text blocks in
convertToOpenAiMessages()when processing user messages:{ type: "text", text: "" }) are filtered outChanges
src/api/transform/openai-format.ts- Added filtering logicsrc/api/transform/__tests__/openai-format.spec.ts- Added 3 test casesTesting
PostHog Issue
https://us.posthog.com/error_tracking/019bbc67-ebdc-7640-967c-df1c8f43172b
Linear Issue
ROO-528
Important
Filters out empty text blocks in
convertToOpenAiMessages()to prevent errors with Gemini models, with new tests added.convertToOpenAiMessages()inopenai-format.tsto prevent errors with Gemini models.openai-format.spec.tsto verify filtering logic.This description was created by
for 4928810. You can customize this summary. It will automatically update as commits are pushed.