Skip to content

fix(v3): preserve provider for structured output - #2775

Merged
miguelg719 merged 1 commit into
v3from
fix/v3-anthropic-structured-output
Aug 19, 2026
Merged

miguelg719 merged 1 commit into
v3from
fix/v3-anthropic-structured-output

Conversation

@miguelg719

@miguelg719 miguelg719 commented Aug 19, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • infer provider options from the AI SDK model provider identity
  • preserve Anthropic structured output configuration after LLMProvider removes the model prefix
  • add a regression test for anthropic/claude-opus-4-8 and a patch changeset

Why

LLMProvider passes the bare claude-opus-4-8 model ID to the Anthropic AI SDK provider. AISdkClient previously inferred the provider only from that bare model ID, so extract() omitted structuredOutputMode: auto and did not opt into Anthropic native structured outputs.

Testing

  • pnpm --filter @browserbasehq/stagehand run build:esm
  • pnpm --filter @browserbasehq/stagehand run test:core -- packages/core/dist/esm/tests/unit/aisdk-clients.test.js
  • pnpm --filter @browserbasehq/stagehand run lint
  • mocked HTTP smoke with @ai-sdk/anthropic@2.0.81 confirmed output_config.format.type is json_schema for claude-opus-4-8
  • live V3 LOCAL browser smoke: extract() with anthropic/claude-opus-4-8 returned the expected typed product object through Anthropic's API

@changeset-bot

changeset-bot Bot commented Aug 19, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 4353d5b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@browserbasehq/stagehand Patch
@browserbasehq/stagehand-evals Patch
@browserbasehq/stagehand-server-v3 Patch

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

@miguelg719 miguelg719 added act These changes pertain to the act function observe These changes pertain to the observe function extract These changes pertain to the extract function labels Aug 19, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment

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.

No issues found across 3 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.
Architecture diagram
sequenceDiagram
    participant Client as External Caller
    participant LLMProv as LLMProvider
    participant AISdk as AISdkClient
    participant infer as inferProviderName()
    participant Model as LanguageModelV2
    participant SDK as AI SDK (generateObject)

    Client->>LLMProv: getClient("anthropic/claude-opus-4-8")
    LLMProv->>LLMProv: strip "anthropic/" prefix → bare "claude-opus-4-8"
    LLMProv->>AISdk: create with model "claude-opus-4-8"
    Note over LLMProv,AISdk: Model is from AI SDK, not raw string

    Client->>AISdk: createChatCompletion(options)
    AISdk->>AISdk: resolve model.provider from AI SDK model
    AISdk->>infer: inferProviderName(model)
    Note over Model,infer: NEW: Use model.provider (e.g. "anthropic")<br/>instead of model.modelId (e.g. "claude-opus-4-8")
    infer->>Model: access model.provider
    Model-->>infer: "anthropic"
    alt provider exists
        infer->>infer: split "anthropic" by "." → ["anthropic"]
        infer-->>AISdk: "anthropic"
    else provider missing (fallback)
        infer->>Model: access model.modelId
        Model-->>infer: "claude-opus-4-8"
        infer->>infer: split "claude-opus-4-8" by "/" → ["claude-opus-4-8"]
        infer-->>AISdk: undefined
    end

    AISdk->>AISdk: check if provider is "anthropic"
    alt provider is "anthropic"
        AISdk->>AISdk: set structuredOutputMode to "auto"
        AISdk->>SDK: generateObject() with providerOptions.anthropic.structuredOutputMode
        Note over AISdk,SDK: Correctly enables native Anthropic structured outputs
    else provider is not "anthropic"
        AISdk->>SDK: generateObject() without Anthropic options
    end

    SDK-->>AISdk: structured output result
    AISdk-->>Client: completion response
Loading

Re-trigger cubic

@miguelg719
miguelg719 merged commit b954a46 into v3 Aug 19, 2026
931 of 966 checks passed
@github-actions github-actions Bot mentioned this pull request Aug 19, 2026
miguelg719 pushed a commit that referenced this pull request Aug 20, 2026
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to v3, this PR will
be updated.


# Releases
## @browserbasehq/stagehand@3.7.2

### Patch Changes

- [#2775](#2775)
[`b954a46`](b954a46)
Thanks [@miguelg719](https://github.com/miguelg719)! - Fix Anthropic
structured output options for provider-prefixed models

- [#2767](#2767)
[`98fa7a4`](98fa7a4)
Thanks [@miguelg719](https://github.com/miguelg719)! - Fix: Normalize
CUA coordinates to actual viewport

- [#2385](#2385)
[`7566804`](7566804)
Thanks [@miguelg719](https://github.com/miguelg719)! - Add `useTouch`
option to actuate agent clicks as trusted touch

## @browserbasehq/stagehand-evals@2.1.1

### Patch Changes

- Updated dependencies
\[[`b954a46`](b954a46),
[`98fa7a4`](98fa7a4),
[`7566804`](7566804)]:
    -   @browserbasehq/stagehand@3.7.2

## @browserbasehq/stagehand-server-v3@3.7.4

### Patch Changes

- Updated dependencies
\[[`b954a46`](b954a46),
[`98fa7a4`](98fa7a4),
[`7566804`](7566804)]:
    -   @browserbasehq/stagehand@3.7.2

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

act These changes pertain to the act function extract These changes pertain to the extract function observe These changes pertain to the observe function

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants