What is extract()?
- TypeScript
- Python
- Go
extract() grabs structured data from a webpage. Every call takes an instruction and an output shape: Zod in TypeScript, Pydantic in Python, and a Go type parameter whose JSON Schema Stagehand derives automatically. Stagehand validates the result against that shape before returning it, so what you get back is already typed.
Why use extract()?
Structured
Turn messy webpage data into clean objects that follow a schema.
Resilient
Build resilient extractions that don’t break when the website changes
Return value
extract() returns a result with two fields: data holds the extracted value, and metadata carries the action ID and server-side cache status. The shape of data follows the schema or Go type you supplied:
- Basic schema
- Array
- Primitive
When extracting with an object schema, the return type is inferred from that schema:Example result:
- TypeScript
- Python
- Go
- TypeScript
- Python
- Go
Advanced configuration
You can pass additional options to configure the model, timeout, locator scope, and whether to include a screenshot:- TypeScript
- Python
- Go
Server-side caching
cache requires a Browserbase browser and a Browserbase API key. It has no effect on local browsers.extract() results server-side. Repeated calls with the same inputs return instantly without consuming LLM tokens. Enable caching on Stagehand.create() and override it per call:
Locator-scoped extractions, including calls with locator or ignoreLocators, bypass the server-side cache and report metadata.cache.status as DISABLED.
- TypeScript
- Python
- Go
Targeted extract
Pass a page locator toextract to target a specific element on the page.
- TypeScript
- Python
- Go
- TypeScript
- Python
- Go
ignoreLocators remove each resolved locator target and its descendants from the snapshot. A locator without nth removes all matching targets; a locator with nth removes only that indexed match. The locator option scopes extraction to one resolved subtree, using nth when present.
Scoped extract currently supports CSS and XPath locators. text= locators are supported by locator methods, but not yet by extract snapshot scoping.Visual extract
Turn the screenshot option on when the extraction needs visual information from the current viewport in addition to the page accessibility tree.- TypeScript
- Python
- Go
The screenshot option captures the current viewport, not the full page. Visual extractions always bypass the server-side cache, because a cache key is built from DOM state and cannot represent the pixels the model saw.
Best practices
Extract with context
You can provide additional context to your schema to help the model extract the data more accurately.- TypeScript
- Python
- Go
Link extraction
To extract links or URLs, define the relevant field as a URL type.
extract call might look for extracting a link or URL. This also works for image links.
- TypeScript
- Python
- Go
Troubleshooting
Empty or partial results
Empty or partial results
Problem:
extract() returns empty or incomplete dataSolutions:- Check your instruction clarity: Make sure your instruction is specific and describes exactly what data you want to extract
- Verify the data exists: Use
observe()first to confirm the data is present on the page - Wait for dynamic content: If the page loads content dynamically, wait for it before extracting
- TypeScript
- Python
- Go
Schema validation errors
Schema validation errors
Problem: Getting schema validation errors or type mismatchesSolutions:
- Use optional fields: Make fields optional if the data might not always be present
- Use flexible types: Consider using a string instead of a number for prices that might include currency symbols
- Add descriptions: Describe each field to help the model understand its requirements
- TypeScript
- Python
- Go
Inconsistent results
Inconsistent results
Problem: Extraction results vary between runsSolutions:
- Be more specific in instructions: Instead of “extract prices”, use “extract the numerical price value for each item”
- Use context in schema descriptions: Add field descriptions to guide the model
- Combine with observe: Use
observe()to understand the page structure first
- TypeScript
- Python
- Go
Performance issues
Performance issues
Problem: Extraction is slow or timing outSolutions:
- Reduce scope: Extract smaller chunks of data in multiple calls rather than everything at once
- Use targeted instructions: Be specific about which part of the page to focus on
- Consider pagination: For large datasets, extract one page at a time
- Increase timeout: Use the timeout option for complex extractions
- TypeScript
- Python
- Go
Next steps
Act
Execute actions efficiently
Observe
Analyze pages and preview actions

