Skip to content

LLM provider integrations for structured outputs in Python

Choose the service that hosts your model to find its SDK and credentials. For the string to pass to from_provider, see model IDs by provider.

Common Features

Feature Description Documentation
Model Patching Enhance provider clients with structured output capabilities Patching
Response Models Define expected response schema with Pydantic Models
Validation Ensure responses match your schema definition Validation
Streaming Stream partial or iterative responses Partial, Iterable
Hooks Add callbacks for monitoring and debugging Hooks

Provider Modes

Use the mode comparison to check whether your provider accepts tool calls, a JSON schema, or JSON instructions in the prompt.

Getting Started

Install instructor and set OPENAI_API_KEY to run this example.

import instructor
from pydantic import BaseModel

class UserInfo(BaseModel):
    name: str
    age: int

client = instructor.from_provider("openai/gpt-6-luna")
response = client.create(
    response_model=UserInfo,
    messages=[{"role": "user", "content": "Extract the name and age. Mina is 32."}],
    reasoning_effort="none",
)

Provider Checklist

  1. Install the SDK and configure credentials as shown in your provider's guide.
  2. Choose a model ID and pass "provider/model" to from_provider.
  3. For asynchronous requests, set async_client=True and await client.create(...).

2. Manual Client Setup

If you already have an SDK client, use the matching Instructor factory. For example, wrap an OpenAI client with from_openai.

import instructor
from openai import OpenAI

client = instructor.from_openai(OpenAI(), model="gpt-6-luna")

Need Help?

Browse the examples, search GitHub issues, or join the Discord community.