-
Couldn't load subscription status.
- Fork 3.2k
Description
Description
When using Anthropic models through AWS Bedrock with citations enabled, the SDK returns empty responses because it doesn't handle CitationsContentBlock types in the response stream.
Steps to Reproduce
- Configure the Vercel AI SDK to use an Anthropic model via Bedrock
- Enable citations in the provider options:
providerOptions: {
bedrock: {
citations: { enabled: true },
},
}- Make a request that would benefit from citations (e.g., with PDF documents)
- Observe that the response is empty
Expected Behavior
When citations are enabled, the SDK should:
- Parse
CitationsContentBlockfrom the Bedrock response - Extract the text content from within the citations block
- Return the complete response to the user (ideally with citation metadata)
Actual Behavior
The SDK doesn't properly process the message part if it is a Bedrock CitationsContentBlock and an empty part is returned.
Root Cause
Bedrock's response format changes when citations are enabled:
- Without citations: Returns
TextBlockobjects - With citations: Returns
CitationsContentBlockobjects
The current implementation doesn't account for this alternative block type, causing the text content to be ignored.
Proposed Solution
Add handling for CitationsContentBlock in the response parser. The block structure typically includes:
- Citation metadata
- The actual text content
- References to source documents
The parser should extract both the text and (optionally) preserve citation information for downstream use.
I'm in the process of creating a PR - Example code:
// citations
if (part.citationsContent) {
for (const generatedContent of part.citationsContent.content) {
// Push the citation generated content (text block) as text to prevent an empty response when citations are present
content.push({
type: 'text',
text: generatedContent.text,
// provide actual citations in providerMetadata
providerMetadata: {
bedrock: {
citations: part.citationsContent.citations
},
},
});
}
}Additional Context
Enabling citations significantly improves Anthropic models' ability to work with PDF documents and other source materials in Bedrock, making this feature valuable for RAG applications.
AI SDK Version
Example:
- @ai-sdk/bedrock: latest
Code of Conduct
- I agree to follow this project's Code of Conduct