3.6 KiB
title, description
| title | description |
|---|---|
| Installing Instructor for LLM Structured Outputs | Complete installation guide for Instructor with support for OpenAI, Anthropic, Google, and 15+ LLM providers. Get started in minutes. |
Instructor Installation Guide: Setup for LLM Structured Outputs
Learn how to install Instructor, the leading Python library for extracting structured data from LLMs like GPT-4, Claude, and Gemini. This comprehensive installation tutorial covers all major LLM providers and gets you ready for production use.
Quick Start: Install Instructor for LLM Development
Get started with structured LLM outputs in seconds. Install Instructor using pip:
pip install instructor
Instructor leverages Pydantic for type-safe LLM data extraction:
pip install pydantic
Pro Tip: Use
uvfor faster installation:uv pip install instructor
LLM Provider Installation Guide
Instructor supports 15+ LLM providers. Here's how to install and configure each:
OpenAI (GPT-4, GPT-3.5)
OpenAI is the default LLM provider for Instructor. Perfect for GPT-4 and GPT-3.5-turbo structured outputs:
pip install instructor
Configure your OpenAI API key for LLM access:
export OPENAI_API_KEY=your_openai_key
Anthropic Claude LLM Setup
Extract structured data from Claude 3 models (Opus, Sonnet, Haiku) with native tool support:
pip install "instructor[anthropic]"
Configure Claude API access:
export ANTHROPIC_API_KEY=your_anthropic_key
Google Gemini LLM Integration
Use Gemini Pro and Flash models for structured outputs with function calling:
pip install "instructor[google-genai]"
Set up Gemini API access:
export GOOGLE_API_KEY=your_google_key
Cohere
To use with Cohere's models:
pip install "instructor[cohere]"
Set up your Cohere API key:
export COHERE_API_KEY=your_cohere_key
Mistral
To use with Mistral AI's models:
pip install "instructor[mistralai]"
Set up your Mistral API key:
export MISTRAL_API_KEY=your_mistral_key
LiteLLM (Multiple Providers)
To use LiteLLM for accessing multiple providers:
pip install "instructor[litellm]"
Set up API keys for the providers you want to use.
Verify Your Instructor LLM Setup
Test your Instructor installation with this simple LLM structured output example:
import instructor
from pydantic import BaseModel
class Person(BaseModel):
name: str
age: int
client = instructor.from_provider("openai/gpt-5-nano")
person = client.create(
model="gpt-5.4-mini",
response_model=Person,
messages=[
{"role": "user", "content": "John Doe is 30 years old"}
]
)
print(f"Name: {person.name}, Age: {person.age}")
Next Steps in Your LLM Tutorial Journey
With Instructor installed, you're ready to build powerful LLM applications:
- Create Your First LLM Extraction - Build structured outputs with any LLM
- Master Response Models - Learn Pydantic models for LLM data validation
- Configure LLM Clients - Set up OpenAI, Anthropic, Google, and more
Common Installation Issues
- Import Errors: Ensure you've installed the provider-specific extras (e.g.,
instructor[anthropic]) - API Key Issues: Verify your environment variables are set correctly
- Version Conflicts: Use
pip install --upgrade instructorto get the latest version
Ready to extract structured data from LLMs? Continue to Your First Extraction →