# Instructor & Pydantic Tooling

Structured data extraction & type-safe LLM function schemas

Instructor enforces strict Pydantic and Zod schemas on LLM outputs, turning unstructured web and API data into typed objects with automatic retries.

## Overview

- **Website**: https://python.useinstructor.com
- **Docs**: https://python.useinstructor.com
- **GitHub**: https://github.com/jxnl/instructor
- **License / Pricing**: Open Source
- **Directory Entry**: https://agentaccess.dk/enablers/instructor

## About

Instructor is the gold standard for getting structured, type-safe data out of LLMs. When parsing Danish government PDF reports, unstructured HTML, or legacy XML APIs, Instructor guarantees the response matches your schema with validation rules and automatic self-correction on error.

## Key Features

- Enforces Pydantic (Python) or Zod (TypeScript) validation
- Automatic retry with self-healing error prompts
- Supports streaming structured partial objects
- Compatible with OpenAI, Anthropic, Gemini, and Ollama

## Danish System Application Recipes

### Extract Danish Company Accounting Metrics into Pydantic
Define a Pydantic schema for Danish solvency, EBITDA, and equity, and extract structured data directly from annual PDF reports.

```bash
from pydantic import BaseModel
import instructor
from openai import OpenAI

class DanishFinancials(BaseModel):
    cvr: str
    year: int
    ebitda_dkk: float
    equity_dkk: float

client = instructor.from_openai(OpenAI())
data = client.chat.completions.create(
    model="gpt-4o",
    response_model=DanishFinancials,
    messages=[{"role": "user", "content": "Extract financials from this text..."}],
)
```

## Quickstart

```python
import instructor
from openai import OpenAI
from pydantic import BaseModel

class DanishAddress(BaseModel):
    street: str
    house_number: str
    postal_code: int
    city: str

client = instructor.from_openai(OpenAI())
addr = client.chat.completions.create(
    model="gpt-4o",
    response_model=DanishAddress,
    messages=[{"role": "user", "content": "Rådhuspladsen 1, 1550 København V"}],
)
print(addr.city)
```

---
Source: [AgentAccess Enablers](https://agentaccess.dk/enablers/instructor)