Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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/olive-colts-sparkle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ai-sdk/amazon-bedrock": patch
---

feat(bedrock): support native structured output for anthropic models without reasoning
59 changes: 59 additions & 0 deletions packages/amazon-bedrock/src/bedrock-chat-language-model.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4564,6 +4564,65 @@
expect(result.providerMetadata?.bedrock?.isJsonResponseFromTool).toBe(true);
});

it('should use native output_config.format for models with structured output support even without thinking enabled', async () => {
server.urls[newerAnthropicGenerateUrl].response = {

Check failure on line 4568 in packages/amazon-bedrock/src/bedrock-chat-language-model.test.ts

View workflow job for this annotation

GitHub Actions / TypeScript

Cannot find name 'newerAnthropicGenerateUrl'. Did you mean 'anthropicGenerateUrl'?
type: 'json-value',
body: {
output: {
message: {
content: [{ text: '{"name":"Test"}' }],
role: 'assistant',
},
},
usage: { inputTokens: 4, outputTokens: 10, totalTokens: 14 },
stopReason: 'end_turn',
},
};

await newerAnthropicModel.doGenerate({

Check failure on line 4582 in packages/amazon-bedrock/src/bedrock-chat-language-model.test.ts

View workflow job for this annotation

GitHub Actions / TypeScript

Cannot find name 'newerAnthropicModel'. Did you mean 'anthropicModelId'?
prompt: [
{
role: 'user',
content: [{ type: 'text', text: 'Generate a name' }],
},
],
responseFormat: {
type: 'json',
schema: {
type: 'object',
properties: {
name: { type: 'string' },
},
required: ['name'],
},
},
});

const requestBody = await server.calls[0].requestBodyJson;

expect(requestBody.toolConfig).toBeUndefined();

expect(requestBody.additionalModelRequestFields?.output_config)
.toMatchInlineSnapshot(`
{
"format": {
"schema": {
"properties": {
"name": {
"type": "string",
},
},
"required": [
"name",
],
"type": "object",
},
"type": "json_schema",
},
}
`);
});

it('should extract reasoning text with signature', async () => {
server.urls[generateUrl].response = {
type: 'json-value',
Expand Down
5 changes: 4 additions & 1 deletion packages/amazon-bedrock/src/bedrock-chat-language-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,12 @@
bedrockOptions.reasoningConfig?.type === 'enabled' ||
bedrockOptions.reasoningConfig?.type === 'adaptive';

const { supportsStructuredOutput: modelSupportsStructuredOutput } =
getModelCapabilities(this.modelId);

Check failure on line 145 in packages/amazon-bedrock/src/bedrock-chat-language-model.ts

View workflow job for this annotation

GitHub Actions / TypeScript

Cannot find name 'getModelCapabilities'.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

getModelCapabilities is called but never defined or imported in bedrock-chat-language-model.ts, causing a ReferenceError at runtime when any Bedrock model is used with structured output or thinking features.

Fix on Vercel


const useNativeStructuredOutput =
isAnthropicModel &&
isThinkingEnabled &&
(modelSupportsStructuredOutput || isThinkingEnabled) &&
responseFormat?.type === 'json' &&
responseFormat.schema != null;

Expand Down
Loading