Skip to content

Conversation

@lewwolfe
Copy link
Contributor

@lewwolfe lewwolfe commented Oct 28, 2025

Background

When using Anthropic models through AWS Bedrock with citations enabled (via providerOptions.bedrock.citations.enabled), the SDK returns empty responses. This is because Bedrock changes its response format when citations are enabled - instead of returning TextBlock objects, it returns CitationsContentBlock objects. The current implementation only handles TextBlock types, causing the text content within citation blocks to be ignored.

Enabling citations significantly improves Anthropic models' ability to work with PDF documents and other source materials in Bedrock, making this an important feature for RAG applications.

Summary

  • Added support for parsing CitationsContentBlock in Bedrock responses
  • Updated the response stream handler to extract text content from citation blocks
  • Ensured backward compatibility with existing TextBlock responses

Manual Verification

  1. Created a test setup with AWS Bedrock using an Anthropic Claude model
  2. Configured the provider with citations enabled:
    providerOptions: {
      bedrock: {
        citations: { enabled: true },
      },
    }
  3. Sent a request with PDF documents attached
  4. Verified that:
    • Responses now contain the expected text content (previously empty)
    • Citations metadata is preserved in the response structure
    • Standard requests without citations continue to work as before
    • No errors occur when processing citation blocks

Checklist

  • Tests have been added / updated (for bug fixes / features)
  • Documentation has been added / updated (for bug fixes / features)
  • A patch changeset for relevant packages has been added (for bug fixes / features - run pnpm changeset in the project root)
  • I have reviewed this pull request (self-review)

Related Issues

Fixes #9823

@gr2m gr2m enabled auto-merge (squash) October 28, 2025 17:26
Copy link
Collaborator

@gr2m gr2m left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for submitting another great PR to the anthropic provider!

Could you please update tests and add or update an example (in examples/ai-core/generate-text) to cover the new functionality?

@gr2m gr2m changed the title Fix (bedrock) - Empty responses when enabling Bedrock citations for Anthropic models [Issue #9823] fix(bedrock): Empty responses when enabling Bedrock citations for Anthropic models Oct 28, 2025
@gr2m gr2m added bug Something isn't working ai/provider provider/anthropic labels Oct 28, 2025
auto-merge was automatically disabled October 29, 2025 14:23

Head branch was pushed to by a user without write access

lewwolfe and others added 2 commits October 29, 2025 15:49
Co-authored-by: vercel[bot] <35613825+vercel[bot]@users.noreply.github.com>
@lewwolfe
Copy link
Contributor Author

@gr2m Tests and documentation is now added, went ahead and fixed the streaming version too and refactored to align with the anthropic provider

@lewwolfe lewwolfe requested a review from gr2m October 29, 2025 15:51
@lewwolfe
Copy link
Contributor Author

lewwolfe commented Nov 3, 2025

@gr2m just in case you missed it, this is ready for review and merging

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Empty responses when enabling Bedrock citations for Anthropic models

2 participants