
Instructor Has a Free Library That Forces LLMs to Return Structured Data
LLMs return strings. Your application needs objects. Instructor patches OpenAI's client to return validated, typed data structures using Pydantic models. No more parsing JSON from markdown blocks. What Instructor Gives You for Free Structured extraction — LLM outputs validated against Pydantic/Zod schemas Automatic retries — if validation fails, it re-prompts with the error Streaming — partial objects stream as they're generated Multiple providers — OpenAI, Anthropic, Google, Mistral, Ollama, LiteLLM Python & TypeScript — first-class support for both Lightweight — patches existing clients, not a framework Quick Start (Python) pip install instructor openai import instructor from openai import OpenAI from pydantic import BaseModel client = instructor . from_openai ( OpenAI ()) class User ( BaseModel ): name : str age : int email : str user = client . chat . completions . create ( model = " gpt-4o-mini " , response_model = User , messages = [{ " role " : " user " , " content " : " Extract
Continue reading on Dev.to Python
Opens in a new tab



