Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
c027978
Create citations schema and implement push of text content as default…
lewwolfe Oct 27, 2025
c45e03e
Merge branch 'vercel:main' into fix-bedrock-citations
lewwolfe Oct 27, 2025
c5949b5
fix citation error in bedrock stream schema
lewwolfe Oct 28, 2025
627013e
change set
lewwolfe Oct 28, 2025
f56ff63
Merge branch 'main' into fix-bedrock-citations
lewwolfe Oct 28, 2025
fa97f40
Apply suggestion from @gr2m
gr2m Oct 28, 2025
3a61bad
style: prettier
vercel-ai-sdk[bot] Oct 28, 2025
0782360
Merge branch 'main' into fix-bedrock-citations
lewwolfe Oct 29, 2025
cdfcc9b
Merge branch 'main' into fix-bedrock-citations
lewwolfe Oct 29, 2025
573d7b6
Update generateText to match anthropic implementation
lewwolfe Oct 29, 2025
9bff0ee
Merge branch 'main' into fix-bedrock-citations
lewwolfe Oct 29, 2025
97e861f
Allow streaming to handle citations like anthropic
lewwolfe Oct 29, 2025
1fee15e
just send back the whole bedrock citation
lewwolfe Oct 29, 2025
f5e32c4
fix generateId issue
lewwolfe Oct 29, 2025
4e56ad3
Implement tests for new code
lewwolfe Oct 29, 2025
2bf8130
Update examples/ai-core/src/generate-text/amazon-bedrock-citations.ts
lewwolfe Oct 29, 2025
991dbda
Merge branch 'main' into fix-bedrock-citations
lewwolfe Oct 29, 2025
b15e5cb
Update structures
lewwolfe Oct 29, 2025
33ead4e
Fix anthropic test structure for bedrock
lewwolfe Oct 29, 2025
eaaf1d1
Add chunk option for location
lewwolfe Oct 29, 2025
7a7d4f1
Merge branch 'main' into fix-bedrock-citations
lewwolfe Oct 30, 2025
c214db7
Merge branch 'main' into fix-bedrock-citations
lewwolfe Oct 30, 2025
a33eb7a
Merge branch 'main' into fix-bedrock-citations
lewwolfe Oct 31, 2025
6a7ca94
Merge branch 'main' into fix-bedrock-citations
lewwolfe Nov 3, 2025
62afa64
Merge branch 'main' into fix-bedrock-citations
lewwolfe Nov 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/wet-geese-remain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@ai-sdk/amazon-bedrock': minor
---

Fix empty responses when bedrock claude citations object is returned
54 changes: 54 additions & 0 deletions packages/amazon-bedrock/src/bedrock-chat-language-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,23 @@ export class BedrockChatLanguageModel implements LanguageModelV3 {
}
}

// 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
},
},
});
}
}

// reasoning
if (part.reasoningContent) {
if ('reasoningText' in part.reasoningContent) {
Expand Down Expand Up @@ -798,6 +815,39 @@ const BedrockRedactedReasoningSchema = z.object({
data: z.string(),
});

const DocumentLocationSchema = z.object({
documentIndex: z.number(),
start: z.number().min(0),
end: z.number().min(0),
});

const BedrockCitationLocationSchema = z.object({
documentChar: DocumentLocationSchema.nullish(),
documentPage: DocumentLocationSchema.nullish(),
documentChunk: DocumentLocationSchema.nullish(),
});

const BedrockCitationSchema = z.object({
title: z.string().nullish(),
sourceContent: z
.array(
z.object({
text: z.string(),
}),
)
.nullish(),
location: BedrockCitationLocationSchema.nullish(),
});

const BedrockCitationsContentSchema = z.object({
content: z.array(
z.object({
text: z.string(),
}),
),
citations: z.array(BedrockCitationSchema),
});

// limited version of the schema, focused on what is needed for the implementation
// this approach limits breakages when the API changes and increases efficiency
const BedrockResponseSchema = z.object({
Expand All @@ -812,6 +862,7 @@ const BedrockResponseSchema = z.object({
z.object({
text: z.string().nullish(),
toolUse: BedrockToolUseSchema.nullish(),
citationsContent: BedrockCitationsContentSchema.nullish(),
reasoningContent: z
.union([
z.object({
Expand Down Expand Up @@ -859,6 +910,9 @@ const BedrockStreamSchema = z.object({
z.object({
reasoningContent: z.object({ data: z.string() }),
}),
z.object({
citation: BedrockCitationSchema,
}),
])
.nullish(),
})
Expand Down
Loading