Skip to content

fix: 12980 align nativeStructuredOuptut across bedrock and anthropic#12981

Closed
heiwen wants to merge 2 commits intovercel:mainfrom
heiwen:1290-align-native-structured-output
Closed

fix: 12980 align nativeStructuredOuptut across bedrock and anthropic#12981
heiwen wants to merge 2 commits intovercel:mainfrom
heiwen:1290-align-native-structured-output

Conversation

@heiwen
Copy link
Copy Markdown
Contributor

@heiwen heiwen commented Mar 2, 2026

Background

@ai-sdk/anthropic and @ai-sdk/amazon-bedrock had different decision logic for Anthropic structured outputs.
In Bedrock, native structured output (output_config.format) was tied to reasoning being enabled, which caused supported models to fall back to JSON tool mode when reasoning was off. This made behavior inconsistent and less reliable.

Summary

  • Updated Bedrock Anthropic structured output selection to use model capability instead of reasoning state.
  • Kept the capability helper in bedrock-chat-language-model simple (explicit -4-<minor> style detection), including 4-1 support and excluding date-based 4-2025... variants.
  • Added/updated tests in bedrock-chat-language-model.test.ts to cover:
    • supported model native output with thinking
    • supported model native output without thinking
    • 4-1 model native output
    • date-based 4-20250514 fallback to JSON tool

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)

Future Work

Extract and share Anthropic structured-output capability detection from a single internal source so Bedrock and Anthropic providers cannot drift.

Related Issues

Fixes #12980

@tigent tigent bot added ai/provider related to a provider package. Must be assigned together with at least one `provider/*` label bug Something isn't working as documented provider/amazon-bedrock Issues related to the @ai-sdk/amazon-bedrock provider provider/anthropic Issues related to the @ai-sdk/anthropic provider labels Mar 2, 2026
@heiwen heiwen force-pushed the 1290-align-native-structured-output branch from 42191a9 to 1b1907e Compare April 2, 2026 08:35
Comment on lines +990 to +999
function supportsAnthropicNativeStructuredOutput(modelId: string): boolean {
// only version 4+ supports structured output
const v = modelId.indexOf('-4-');
if (v < 0) return false;

// versions before 4-1 don't suport structured outputs yet
// reject bedrock style claude-opus-4-20250514-v1:0
return modelId[v + 3] !== '-' && modelId[v + 4] === '-';
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

imo this is very brittle logic. we would keep coming back to this whenever newer models are added

Comment on lines +86 to +94
const supportedStructuredOutputGenerateUrl = `${baseUrl}/model/${encodeURIComponent(
supportedStructuredOutputModelId,
)}/converse`;
const supportedStructuredOutput41GenerateUrl = `${baseUrl}/model/${encodeURIComponent(
supportedStructuredOutput41ModelId,
)}/converse`;
const dateBasedStructuredOutput4GenerateUrl = `${baseUrl}/model/${encodeURIComponent(
dateBasedStructuredOutput4ModelId,
)}/converse`;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

not sure why we have to create these 3 vars globally instead of locally in the tests

@aayush-kapoor
Copy link
Copy Markdown
Collaborator

closed in favour of #14126

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

Labels

ai/provider related to a provider package. Must be assigned together with at least one `provider/*` label bug Something isn't working as documented provider/amazon-bedrock Issues related to the @ai-sdk/amazon-bedrock provider provider/anthropic Issues related to the @ai-sdk/anthropic provider

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Claude 4.x on Bedrock provider doesn't use nativeStructuredOutput, even though supported

2 participants