Skip to content

Add back default extract schema - #2562

Merged
miguelg719 merged 11 commits into
v4-spikefrom
miguelgonzalez/stg-2747-add-back-default-extract-schema
Aug 4, 2026
Merged

Add back default extract schema#2562
miguelg719 merged 11 commits into
v4-spikefrom
miguelgonzalez/stg-2747-add-back-default-extract-schema

Conversation

@miguelg719

@miguelg719 miguelg719 commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • default extract calls to an object with a required string extraction field in TypeScript and Python
  • use the same schema when Go callers pass a nil schema
  • preserve explicit schema validation and add wire-level regression coverage for all three SDKs

Verification

  • TypeScript: object-wrapper suite (42 passed), formatting, lint
  • Python: ruff, ty, full pytest suite (263 passed, 1 skipped)
  • Go: focused extract and envelope regression tests

Notes

  • The broader TypeScript unit run reached 117 passing tests; its package-contract test could not complete its isolated dependency install in this environment.
  • The TypeScript package build compiled JS and declarations successfully, then stopped because the generated extension artifact was not present.

Summary by cubic

Restore a protocol-level default extract schema so extract() works without a schema and returns { extraction: string } by default across @browserbasehq/stagehand, @browserbasehq/stagehand-python, and @browserbasehq/stagehand-go. Makes the schema optional in the protocol and server, adds type-safe defaults/overloads, and updates docs/tests for Linear STG-2747.

  • New Features

    • Protocol/server: embed default JSON schema ({ extraction: string }), make schema optional, and apply the default in the router and wire models.
    • TypeScript (@browserbasehq/stagehand): default to DefaultExtractDataSchema when no Zod schema is provided, accept options as the second arg, validate with the chosen schema, and only send schema when custom.
    • Python (@browserbasehq/stagehand-python): add DefaultExtract model and overload; generated params default to the protocol schema; only send schema when custom.
    • Go (@browserbasehq/stagehand-go): omit schema by default via omitempty; client sets params only when a custom schema is provided.
    • Docs/tests: mark schema optional and document the default; adjust TS docs/tests to reflect schema-bearing overload return type; add server/protocol and SDK tests for default behavior.
  • Bug Fixes

    • Go: preserve an explicitly empty schema ({}) and ensure it is sent on the wire.

Written for commit 838df58. Summary will update on new commits.

Review in cubic

@changeset-bot

changeset-bot Bot commented Aug 3, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 838df58

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@miguelg719 miguelg719 changed the title [STG-2747] Add back default extract schema Add back default extract schema Aug 3, 2026
@miguelg719
miguelg719 requested a review from a team as a code owner August 3, 2026 22:17

@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.

All reported issues were addressed

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread packages/sdk-go/stagehand.go Outdated
Comment thread packages/sdk-python/src/stagehand/stagehand.py
Comment thread packages/sdk-go/behavior_regression_test.go

@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.

All reported issues were addressed across 3 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread packages/sdk-ts/src/stagehand.ts
@miguelg719
miguelg719 force-pushed the miguelgonzalez/stg-2747-add-back-default-extract-schema branch 2 times, most recently from 46af76b to 1fa988f Compare August 3, 2026 22:53
@miguelg719

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai

@cubic-dev-ai

cubic-dev-ai Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai

@miguelg719 I have started the AI code review. It will take a few minutes to complete.

@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.

All reported issues were addressed across 10 files

Architecture diagram
sequenceDiagram
    participant TSClient as TypeScript SDK Client
    participant PyClient as Python SDK Client
    participant GoClient as Go SDK Client
    participant Stagehand as Stagehand (core)
    participant ProtocolRPC as Protocol RPC Client
    participant DocSite as Documentation Site

    Note over TSClient,GoClient: PR: Default extract schema across all 3 SDKs

    alt TypeScript call with no schema
        TSClient->>TSClient: Uses defaultExtractSchema (z.object({ extraction: z.string() }))
        TSClient->>Stagehand: extract(instruction, schema = undefined)
        Stagehand->>Stagehand: resolvedSchema = defaultExtractSchema
        Stagehand->>Stagehand: Generate JSON schema from resolvedSchema
        Stagehand->>ProtocolRPC: stagehand.extract with schema = { type: "object", properties: { extraction: { type: "string" } }, required: ["extraction"], additionalProperties: false }
        ProtocolRPC-->>Stagehand: ExtractResult { data: { extraction: "..." } }
        Stagehand->>Stagehand: Parse response with resolvedSchema
        Stagehand-->>TSClient: ExtractResult<typeof defaultExtractSchema>
    else Python call with default schema class
        PyClient->>PyClient: Uses DefaultExtract model
        PyClient->>Stagehand: extract(instruction, schema = DefaultExtract)
        Stagehand->>Stagehand: schema is DefaultExtract → use _DEFAULT_EXTRACT_SCHEMA dict
        Stagehand->>ProtocolRPC: stagehand.extract with schema = { "type": "object", "properties": { "extraction": { "type": "string" } }, "required": ["extraction"], "additionalProperties": false }
        ProtocolRPC-->>Stagehand: ExtractResult { data: { extraction: "..." } }
        Stagehand-->>PyClient: ExtractResult[DefaultExtract]
    else Go call with nil schema
        GoClient->>GoClient: schema parameter = nil
        GoClient->>Stagehand: Extract(instruction, schema = nil)
        Stagehand->>Stagehand: schema == nil → Use defaultExtractSchema() JSON
        Stagehand->>ProtocolRPC: stagehand.extract with schema = { "type": "object", "properties": { "extraction": { "type": "string" } }, "required": ["extraction"], "additionalProperties": false }
        ProtocolRPC-->>Stagehand: ExtractResult { Data: { extraction: "..." } }
        Stagehand-->>GoClient: ExtractResult
    end

    Note over GoClient,GoClient: Explicit empty schema path (Go only)
    alt Go: schema = json.RawMessage{} (empty)
        GoClient->>Stagehand: Extract(instruction, schema = {})
        Stagehand->>Stagehand: schema is not nil → Preserve empty schema
        Stagehand->>ProtocolRPC: stagehand.extract with schema = {}
        ProtocolRPC-->>Stagehand: ExtractResult { Data: {} }
        Stagehand-->>GoClient: ExtractResult with empty data
    end

    Note over TSClient,PyClient: TypeScript: generic overload guard
    alt TS caller tries generic without runtime schema
        TSClient->>TSClient: extract<CustomSchema>(instruction, undefined)
        TSClient->>TSClient: @ts-expect-error – TypeScript prevents this
        Note over TSClient: Compile-time type safety preserved
    end

    DocSite->>DocSite: Updated docs: schema param marked optional, describes default
Loading

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread packages/docs/v4/reference/stagehand.mdx Outdated
Comment thread packages/sdk-ts/src/stagehand.ts Outdated
Comment thread packages/sdk-python/tests/test_stagehand.py
@miguelg719
miguelg719 force-pushed the miguelgonzalez/stg-2747-add-back-default-extract-schema branch 2 times, most recently from e874cab to ba30761 Compare August 4, 2026 19:01
Comment thread .changeset/quiet-pandas-extract.md Outdated

@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.

All reported issues were addressed across 14 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread packages/sdk-go/stagehand.go
Comment thread packages/sdk-python/src/stagehand/_generated/models.py
Comment thread packages/protocol/schemas.ts
@miguelg719
miguelg719 force-pushed the miguelgonzalez/stg-2747-add-back-default-extract-schema branch from a876f77 to fdbf349 Compare August 4, 2026 20:04
@miguelg719
miguelg719 force-pushed the miguelgonzalez/stg-2747-add-back-default-extract-schema branch from fdbf349 to 838df58 Compare August 4, 2026 20:42
@miguelg719
miguelg719 merged commit fdc96a9 into v4-spike Aug 4, 2026
52 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants