Skip to content

Structured output

Structured output asks for a response that matches a Pydantic model, TypedDict, dataclass, or JSON Schema. Your code receives fields instead of scraping sentences.

from pydantic import BaseModel, Field
class Triage(BaseModel):
priority: str = Field(description="low, medium, or high")
reason: str
triage_model = model.with_structured_output(Triage)
result = triage_model.invoke("Payment failed for every customer.")
print(result.priority)

For an agent, pass the schema as response_format=Triage; the validated value appears under result["structured_response"].

A valid object can still be wrong. Schema validation proves shape and types, not factual correctness. Provider support also differs; check whether the integration uses native structured output, tool calling, or another method.

Chat models · Tools and schemas · create_agent