fix: filter empty content blocks for Bedrock provider#14586
fix: filter empty content blocks for Bedrock provider#14586Tom-Ryder wants to merge 2 commits intoanomalyco:devfrom
Conversation
|
The following comment was made by an LLM, it may be inaccurate: Based on my search, I found related PRs but no direct duplicates of PR #14586: Related PRs:
These are related to content filtering improvements, but none appear to be addressing the exact same issue (filtering empty content blocks for Bedrock specifically with the No duplicate PRs found |
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
|
Tested this exact failure pattern in production usage with Bedrock Claude in OpenCode:\n\n |
| return msgs | ||
| .map((msg) => { | ||
| if (msg.role === "assistant" && Array.isArray(msg.content)) { |
There was a problem hiding this comment.
why change this unrelated stuff?
|
|
||
| test("keeps non-text/reasoning parts even if text parts are empty", () => { | ||
| test("drops assistant message that has only reasoning parts", () => { |
There was a problem hiding this comment.
hm im not sure if this one is correct
| @@ -51,7 +51,7 @@ export namespace ProviderTransform { | |||
| ): ModelMessage[] { | |||
| // Anthropic rejects messages with empty content - filter out empty string messages | |||
| // and remove empty text/reasoning parts from array content | |||
| if (model.api.npm === "@ai-sdk/anthropic") { | |||
| if (model.api.npm === "@ai-sdk/anthropic" || model.api.npm === "@ai-sdk/amazon-bedrock") { | |||
There was a problem hiding this comment.
why can't we just have this change +1 test for it, ill cleanup later cause we should be a bit better at doing this across the board but htere was a special case that caused errors in the past
Issue for this PR
Closes #11210
Type of change
What does this PR do?
normalizeMessages()filters empty text/reasoning parts for@ai-sdk/anthropicbut not@ai-sdk/amazon-bedrock. The Bedrock Converse API has the same constraint — empty content arrays cause "content field is empty" and invalid cache point errors that permanently break the session. Extended the existing guard to also cover Bedrock.Note: this fixes the empty content filtering side of #11210. The separate Bedrock ConverseAPI tool call issues flagged in the thread will need a follow-up.
How did you verify your code works?
bun turbo typecheckpassesScreenshots / recordings
N/A — backend logic change.
Checklist