Skip to content

fix(provider): filter empty text content blocks for Bedrock#15777

Closed
zerone0x wants to merge 1 commit intoanomalyco:devfrom
zerone0x:fix/issue-15715-bedrock-empty-text-blocks
Closed

fix(provider): filter empty text content blocks for Bedrock#15777
zerone0x wants to merge 1 commit intoanomalyco:devfrom
zerone0x:fix/issue-15715-bedrock-empty-text-blocks

Conversation

@zerone0x
Copy link
Contributor

@zerone0x zerone0x commented Mar 3, 2026

Summary

Fixes #15715
Fixes #13811

Problem

AWS Bedrock rejects API requests that contain empty text content blocks with:

ValidationException: messages: text content blocks must be non-empty

Root Cause

normalizeMessages() in transform.ts already filters out empty text/reasoning content blocks — but the guard only applied to @ai-sdk/anthropic. AWS Bedrock (@ai-sdk/amazon-bedrock) has the same constraint on the API level, so it was silently passing empty blocks through.

Fix

Extend the existing empty-content filter to cover @ai-sdk/amazon-bedrock as well:

- // Anthropic rejects messages with empty content - filter out empty string messages
+ // Anthropic and Bedrock reject 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") {

Tests

Added a new describe block mirroring the Anthropic empty-content filtering tests for Bedrock, covering:

  • Empty string content messages
  • Empty text parts in array content
  • All-empty messages being removed entirely
  • Non-text/reasoning parts preserved even when text parts are empty

AWS Bedrock rejects messages containing empty text content blocks with
'ValidationException: messages: text content blocks must be non-empty'.

The empty-content filter in normalizeMessages() was only applied to
the @ai-sdk/anthropic provider. Extend it to also cover
@ai-sdk/amazon-bedrock which has the same API constraint.

Fixes anomalyco#15715
@github-actions github-actions bot added the needs:compliance This means the issue will auto-close after 2 hours. label Mar 3, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Mar 3, 2026

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 3, 2026

The following comment was made by an LLM, it may be inaccurate:

I found a potentially related PR:

Related PR:

This appears to be addressing the exact same issue as the current PR #15777. Both are about filtering empty content blocks for the Bedrock provider. You should verify whether #14586 was already merged or closed, and if so, whether the current PR (#15777) is based on or supersedes it.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 3, 2026

This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window.

Feel free to open a new pull request that follows our guidelines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

1 participant