Instructor: The Python Library That Forces LLMs to Output Valid

Stop wrestling with inconsistent LLM outputs. Learn how Instructor patches the OpenAI client to guarantee valid, type-safe JSON responses using Pydantic models. Features retry logic, multi-provider support, and streaming.

  • ⭐ 18000
  • TypeScript
  • MIT
  • Updated 2026-05-20

{{< resource-info >}}

Last updated: May 19, 2026

If you’ve ever tried to get a Large Language Model to consistently output valid JSON, you know the pain. One response is perfect. The next misses a closing brace. The third includes explanatory text before the JSON. The fourth returns valid JSON but with the wrong schema. This inconsistency makes LLMs unreliable for production applications that need structured data — until Instructor arrived on the scene.

Instructor is a Python library that patches the OpenAI client (and 10+ other LLM providers) to guarantee structured, type-safe, validated outputs using Pydantic models. It transforms the wild west of LLM text generation into a predictable, software-engineered process. With 11,000+ GitHub stars, MIT license, and a thriving community, Instructor has become the de facto standard for structured LLM output in Python. This guide covers everything from basic setup to advanced multi-provider patterns in 2026.

💬 Discussion