fix(amazon-bedrock): preserve empty text blocks when reasoning content is present#14175
fix(amazon-bedrock): preserve empty text blocks when reasoning content is present#14175aayush-kapoor merged 2 commits intomainfrom
Conversation
|
@aayush-kapoor For my own edification can you explain why you trim empty text messages at all? Is there some provider that emits many empty text messages and wants them to be trimmed? Besides curiosity, I also want to avoid a situation where some other model provider has this exact same issue, since your fix seems to only be on bedrock but the bedrock team insists this is valid Anthropic model behavior (so may exist on anthropic first party or vertex) |
|
i see that the trimming was introduced in as a part of #7559. so there must've been a reason why it has been added (if you look at the attached issue to the original pr)
we prefer making fixes if/when observed to avoid bloat. and that's why reproduction is critical. if you happen to see the same issue on the anthropic provider, let us know by creating an issue! |
|
Wow, that's so annoying. I will bring this up to the bedrock team. IMO very poor API design to emit empty-ish blocks in text and then error if they are sent back in a text message but error if they aren't sent back in a text message between reasoning blocks. |
…t is present (#14175) ## Background #14071 bedrock's claude models can return assistant messages with empty text blocks sandwiched between reasoning blocks. their API strictly validates that when you replay assistant messages in conversation history, the content blocks must appear in the exact same order. AI SDK was dropping those empty text blocks ## Summary - Added a `hasReasoningBlocks` check so that empty text blocks are only skipped when the message does not contain reasoning blocks. When reasoning blocks are present, empty text blocks are preserved to maintain correct indices. - changed `if (part.text)` to `if (part.text != null)` : the old check silently dropped empty text blocks from the response before they ever entered the SDK's message history ## Manual Verification na ## Checklist - [x] Tests have been added / updated (for bug fixes / features) - [ ] Documentation has been added / updated (for bug fixes / features) - [x] A _patch_ changeset for relevant packages has been added (for bug fixes / features - run `pnpm changeset` in the project root) - [x] I have reviewed this pull request (self-review) ## Related Issues fixes #14071
|
✅ Backport PR created: #14189 |
…ing content is present (#14189) This is an automated backport of #14175 to the release-v6.0 branch. FYI @aayush-kapoor Co-authored-by: Aayush Kapoor <83492835+aayush-kapoor@users.noreply.github.com>
|
🚀 Published in:
|
…t is present (#14175) ## Background #14071 bedrock's claude models can return assistant messages with empty text blocks sandwiched between reasoning blocks. their API strictly validates that when you replay assistant messages in conversation history, the content blocks must appear in the exact same order. AI SDK was dropping those empty text blocks ## Summary - Added a `hasReasoningBlocks` check so that empty text blocks are only skipped when the message does not contain reasoning blocks. When reasoning blocks are present, empty text blocks are preserved to maintain correct indices. - changed `if (part.text)` to `if (part.text != null)` : the old check silently dropped empty text blocks from the response before they ever entered the SDK's message history ## Manual Verification na ## Checklist - [x] Tests have been added / updated (for bug fixes / features) - [ ] Documentation has been added / updated (for bug fixes / features) - [x] A _patch_ changeset for relevant packages has been added (for bug fixes / features - run `pnpm changeset` in the project root) - [x] I have reviewed this pull request (self-review) ## Related Issues fixes #14071
Background
#14071
bedrock's claude models can return assistant messages with empty text blocks sandwiched between reasoning blocks. their API strictly validates that when you replay assistant messages in conversation history, the content blocks must appear in the exact same order.
AI SDK was dropping those empty text blocks
Summary
hasReasoningBlockscheck so that empty text blocks are only skipped when the message does not contain reasoning blocks. When reasoning blocks are present, empty text blocks are preserved to maintain correct indices.if (part.text)toif (part.text != null): the old check silently dropped empty text blocks from the response before they ever entered the SDK's message historyManual Verification
na
Checklist
pnpm changesetin the project root)Related Issues
fixes #14071