[v5.0] fix: Bedrock Claude structured outputs fail with thinking on supported models - #17757
Conversation
Bugfix reviewOutcome: changes-required Reproduction replayStatus: no-longer-reproduces The exact original reproduction completed successfully and the original bug signal did not appear. Fixes issueStatus: partially-addresses The fix works for the reproduced simple schema on supported Claude 4.5/4.6 models, but it applies native structured output to every Anthropic model and forwards schemas that Bedrock may reject. Concerns:
Side effectsRisk: medium Non-thinking and non-Anthropic behavior remains unchanged, but unsupported Anthropic models now receive an unsupported output_config payload instead of the synthetic tool configuration. Concerns:
PerformanceRisk: low The change adds no local caches, loops, or unbounded allocations; native schema compilation is provider-side, although a new schema can have first-use compilation latency. Backwards compatibilityRisk: none The change does not read, migrate, mutate, or reinterpret stored application data. ArchitectureRisk: medium The implementation remains inside the Bedrock provider, but it bypasses an existing Anthropic-owned abstraction required for correctly preparing output_config schemas. Concerns:
Change scopeStatus: has-unnecessary-changes The changeset, provider fix, and regression test are relevant, but one production hunk changes unrelated option-merging behavior. Concerns:
SecurityRisk: none No credential handling, authorization, input execution, network destination, or sensitive-data behavior is introduced. TestingStatus: needs-more The added generate-path regression passes, as do the package Node and edge suites and type-check, but the test uses Claude 3 Haiku and therefore codifies native output for an unsupported model. Concerns:
VerificationReviewed the complete three-file merge-base diff, inspected the provider's request and response paths, compared the existing Anthropic schema sanitizer and later Bedrock implementation, and ran the Amazon Bedrock Node suite, edge suite, type-check, and diff validation successfully. Relevant Documentation
|
|
Addressed PR comment 5047547423.
Restricted native output_config generation to the documented supported Claude model IDs, exported and reused Anthropic's sanitizeJsonSchema helper, and removed the unrelated preservation of arbitrary output_config fields from the maxReasoningEffort branch. The tests now use supported Claude 4.5 and 4.6 IDs and cover constraint sanitization, adaptive thinking with effort, and unsupported models receiving no native output_config. Unsupported models retain the synthetic-tool fallback because Bedrock provides no native structured-output path for them. Node, edge, type, formatting, build, and live fixed/adaptive-thinking checks pass. |
Bugfix reviewOutcome: changes-required Reproduction replayStatus: no-longer-reproduces The exact original reproduction completed successfully and the original bug signal did not appear. Fixes issueStatus: partially-addresses The implementation fixes supported Claude 4.5/4.6 requests in the checkout, but its required cross-package export is not independently releasable with the current changeset. Concerns:
Side effectsRisk: high The runtime logic is narrowly gated, but incorrect package release coordination could prevent the published Bedrock provider from importing at all. Concerns:
PerformanceRisk: low Schema sanitization performs a bounded recursive copy proportional to the supplied schema and introduces no persistent caches, unbounded loops, or retained request state. Backwards compatibilityRisk: none The change does not read, migrate, mutate, or reinterpret existing stored data. ArchitectureRisk: medium Reusing the Anthropic-owned sanitizer through its declared internal export preserves package ownership, but the owning package is missing from the release declaration. Concerns:
Change scopeStatus: unclear The production code and tests are focused, but the release scope is incomplete because the changed Anthropic package is omitted from the changeset. Concerns:
SecurityRisk: none The change introduces no credential handling, authorization changes, executable input, network destination changes, or sensitive-data exposure. TestingStatus: appropriate Regression tests cover fixed and adaptive thinking, schema sanitization, effort merging, native JSON text responses, omission of forced tool configuration, and unsupported-model fallback. VerificationInspected the complete four-file merge-base diff, package exports and dependency boundaries, request and response paths, model gating, schema sanitizer ownership, and release metadata. Amazon Bedrock Node and edge suites each passed all 225 tests, both Amazon Bedrock and Anthropic type checks passed, diff validation passed, and changeset inspection confirmed Anthropic is not declared for this PR's release. Relevant Documentation
|
|
Addressed PR comment 5047547423.
Addressed the model gating, sanitizer ownership, option-merging, and coverage concerns. Native output is restricted to supported Claude 4.5/4.6 IDs, schemas use sanitizeJsonSchema through @ai-sdk/anthropic/internal, unsupported models retain the prior fallback, and tests cover fixed and adaptive thinking, sanitization, effort merging, toolConfig omission, fallback behavior, and JSON text responses. |
|
Addressed PR comment 5047845597.
Added @ai-sdk/anthropic as a patch entry in the existing changeset so the new internal export is released with its Amazon Bedrock consumer. Rebuilt both packages and verified that the built Anthropic internal entry exports sanitizeJsonSchema and the built Bedrock entry imports it successfully. |
Bugfix reviewOutcome: approved Reproduction replayStatus: no-longer-reproduces The exact original reproduction completed successfully and the original bug signal did not appear. Fixes issueStatus: fully-addresses Thinking-enabled structured output now uses sanitized native output_config.format for the Bedrock Claude models documented to support it, while unsupported models retain the existing fallback. Side effectsRisk: low The new behavior is restricted to supported Anthropic models when both thinking and a JSON schema are requested; non-thinking, non-Anthropic, and unsupported-model paths remain unchanged. PerformanceRisk: low Schema sanitization creates a request-scoped copy proportional to schema size and introduces no persistent cache, retained state, or additional network request. Backwards compatibilityRisk: none The change does not read, migrate, mutate, or reinterpret stored application data. ArchitectureRisk: low Anthropic-specific schema normalization remains owned by the Anthropic package and is consumed through its declared internal export; both producer and consumer receive coordinated patch releases, with no cross-package src import. Change scopeStatus: minimal All four changed files are necessary: provider request selection, regression coverage, the owning package's internal export, and coordinated release metadata. SecurityRisk: none The change introduces no credential, authorization, executable-input, network-destination, or sensitive-data handling changes. TestingStatus: appropriate Regression tests cover fixed and adaptive thinking, supported and unsupported model selection, schema sanitization, effort merging, omission of forced toolConfig, and native JSON text responses. VerificationReviewed the complete merge-base diff and relevant package boundaries, confirmed the coordinated changeset, and verified diff integrity, formatting, linting, both package type checks, and the Amazon Bedrock Node and edge suites with all 225 tests passing in each environment. Relevant Documentation
|
|
🚀 Published in:
|
Background
Bedrock structured output used a required synthetic JSON tool, which conflicts with Claude thinking, while supported Claude 4.5 and 4.6 models can use native structured output.
Root Cause
The Bedrock provider always represented JSON schemas as a required synthetic tool, forcing tool use with thinking. Request-shape tests and successful live Bedrock calls confirmed that supported models instead accept sanitized native output_config.format schemas.
Summary
Supported Bedrock Claude models now use sanitized native structured-output schemas when fixed or adaptive thinking is enabled, without toolConfig. Unsupported models retain the existing fallback, the Anthropic sanitizer is exported through @ai-sdk/anthropic/internal, effort settings are preserved, and the changeset patches both packages.
Testing
Regression coverage verifies fixed and adaptive thinking, schema sanitization, effort merging, unsupported-model fallback, omission of forced tool configuration, and returned JSON text. Amazon Bedrock Node and edge suites each pass 225 tests; both package type checks, builds, and formatting checks pass.
End-to-end Validation
AWS_REGION=us-east-1 pnpm --filter @example/ai-core exec tsx -e '<Opus 4.5 fixed-thinking constrained schema>'returned{"answer":"ok","score":1}.AWS_REGION=us-east-1 pnpm --filter @example/ai-core exec tsx -e '<Opus 4.6 adaptive-thinking schema>'returned{"answer":"ok"}.Related Issues
Fixes #11227
Closes #17729
Co-authored-by: lgrammel 205036+lgrammel@users.noreply.github.com