fix(anthropic): filter empty text blocks from assistant messages#9491
Open
ygd58 wants to merge 1 commit into
Open
fix(anthropic): filter empty text blocks from assistant messages#9491ygd58 wants to merge 1 commit into
ygd58 wants to merge 1 commit into
Conversation
Bedrock and strict Anthropic-compatible endpoints reject messages where a text content block has an empty or whitespace-only 'text' field with: ValidationException: messages: text content blocks must be non-empty This happens in multi-turn conversations when context compression or streaming produces an assistant message with an empty text block alongside tool_use blocks. User messages already had this guard (falls back to '(empty message)'). Assistant messages were missing it — converted_content blocks were extended into the final list without filtering empty text entries. Fix: skip text blocks with empty/whitespace 'text' when building the assistant content block list in convert_to_anthropic_messages(). Fixes NousResearch#9486
1 task
Collaborator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
Closes #9486
Bedrock and strict Anthropic-compatible endpoints reject messages where a text content block has an empty
textfield:This happens in multi-turn conversations when an assistant message contains an empty text block alongside tool_use blocks.
Root Cause
In
convert_to_anthropic_messages(), user messages already had an empty-block guard. Assistant messages were missing it —converted_contentblocks were extended into the final list without filtering empty text entries.Fix
Skip text blocks with empty/whitespace
textwhen building the assistant content block list:Before / After
Before: Multi-turn chat with tool calls → empty text block in assistant message → Bedrock 400 error
After: Empty text blocks silently dropped → valid message sent → no error