agent.extract(query: str, schema: dict, model: str | None = None) -> dict | list
Returns data matching a JSON Schema.
Parameters
| Parameter | Type | Default | Description |
|---|
query | str | — | What data to extract from the screen |
schema | dict | — | JSON Schema defining the output format |
model | str | None | None | Override the default model for this call |
Returns
dict | list — Structured data matching the schema.
Raises
WorkflowError — on extraction failure
ValueError — if schema is empty
Examples
Inline schema:
def run(params: Params) -> Result:
agent = Agent()
data = agent.extract(
"What is the page title?",
{"type": "object", "properties": {"title": {"type": "string"}}, "required": ["title"]}
)
Using Pydantic models (recommended):
from pydantic import BaseModel
class ProductInfo(BaseModel):
name: str
price: float
def run(params: Params) -> Result:
agent = Agent()
data = agent.extract("Extract the product details", ProductInfo.model_json_schema())
product = ProductInfo.model_validate(data)
With model override for complex extraction:
def run(params: Params) -> Result:
agent = Agent()
data = agent.extract(
"Extract all visible invoice line items",
InvoiceSchema.model_json_schema(),
model="claude-sonnet-4-5-20250929"
)
Use YourModel.model_json_schema() to generate the schema from your Pydantic models — this keeps your schema in sync with your types.