Claude API · Tools and structured output

Get a validated Python object back

Pass a Pydantic class as output_format and read the parsed object. The response is guaranteed to match the schema.

from pydantic import BaseModel

class ContactInfo(BaseModel):
    name: str
    email: str
    interests: list[str]

response = client.messages.parse(
    model="claude-opus-5-5",
    max_tokens=16000,
    messages=[{"role": "user", "content": "Extract: Jane Doe ([email protected]) likes APIs and SDKs."}],
    output_format=ContactInfo,
)
contact = response.parsed_output

Official Claude API documentation

More tools and structured output commands

All tools and structured output commands · Claude API cheatsheet

Was this page helpful?