Fix structuredOutputMode for newer Anthropic models#2120
Merged
Conversation
🦋 Changeset detectedLatest commit: 6ef2148 The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
structuredOutputMode for newer Anthropic models
Contributor
There was a problem hiding this comment.
1 issue found across 2 files
Confidence score: 3/5
- There is a concrete regression risk in
packages/core/lib/v3/llm/aisdk.ts:structuredOutputMode: "auto"is gated to prefixed Anthropic model IDs, so unprefixedclaude-*IDs may not get the structured-output fix. - Because this is a medium-severity, high-confidence behavior gap (6/10, 8/10) in model routing logic, merge risk is moderate rather than low.
- Pay close attention to
packages/core/lib/v3/llm/aisdk.ts- ensure Anthropic ID matching covers both prefixed and unprefixed forms so structured output behavior is consistent.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="packages/core/lib/v3/llm/aisdk.ts">
<violation number="1" location="packages/core/lib/v3/llm/aisdk.ts:182">
P2: `structuredOutputMode: "auto"` is only applied for prefixed Anthropic model IDs, so unprefixed Anthropic IDs (e.g. `claude-*`) still miss the new structured-output fix.</violation>
</file>
Architecture diagram
sequenceDiagram
participant App as Stagehand App
participant LLMClient as LLMClient
participant AISdkClient as AISdkClient
participant Provider as Provider SDK (Anthropic/Azure)
participant AnthropicAPI as Anthropic API
Note over App,AnthropicAPI: Structured output configuration flow
App->>LLMClient: execute() with structured output schema
LLMClient->>AISdkClient: callModel() with provider options
alt Provider is "anthropic"
AISdkClient->>AISdkClient: Set providerOptions.anthropic.structuredOutputMode = "auto"
AISdkClient->>Provider: call with providerOptions including structuredOutputMode: "auto"
Provider->>AnthropicAPI: API request with tool-use mode (structured output)
AnthropicAPI-->>Provider: Structured JSON response
Provider-->>AISdkClient: Parsed structured output
else Provider is "azure"
AISdkClient->>AISdkClient: Set providerOptions.azure.strictJsonSchema = true
AISdkClient->>Provider: call with strictJsonSchema enabled
Provider-->>AISdkClient: Structured output via strict schema
else Default (no specific provider options)
AISdkClient->>Provider: call without structured output overrides
Provider-->>AISdkClient: Unstructured response (may fail for JSON)
end
AISdkClient-->>LLMClient: Return structured result
LLMClient-->>App: Structured output data
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review, or fix all with cubic.
seanmcguire12
approved these changes
May 14, 2026
This was referenced May 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
why
New output mode
output_formatfrom anthropic breaks compat with olderjsonTool. Opus 4.7 defaults to the new format so it breaks with strict mode settings enabledwhat changed
On
aisdk.tsensuredstructuredOutputModedefaults toauto.test plan
env:LOCALand extract with custom schemaSummary by cubic
Set
providerOptions.anthropic.structuredOutputModetoautofor theanthropicprovider to align with newer Anthropic models. Restores structured outputs and prevents schema/response errors when generating JSON, and adds a patch changeset for@browserbasehq/stagehand.Written for commit 6ef2148. Summary will update on new commits.