Skip to main content
Use tools to get structured, typed responses that you can parse reliably.

The Pattern

Instead of parsing free-form text, define a tool that captures the exact structure you need. The AI will call it with structured data.

Complete Example: Data Extraction Pipeline

Extract structured data from unstructured text:

Classification

Use structured output for classification tasks:

Multiple Extractions

Extract multiple items from a document:

Tips

The AI uses field descriptions to understand what to extract. Be specific.
Stop the loop when your extraction tool is called to avoid extra processing.
Use a mutable dict or list in the outer scope to capture the tool’s arguments.
Always validate extracted data before using it in production.