instructor

Extracts structured JSON from LLM outputs using Pydantic schema validation with automatic retries and optional streaming, supporting OpenAI and Anthropic via Instructor.

Updated May 26, 2026
One-click install
npx skills add https://github.com/ruiyangruiyi/hermes-agent --skill instructor-ruiyangruiyi
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: instructor
Source: https://github.com/ruiyangruiyi/hermes-agent/tree/main/optional-skills/mlops/instructor
Command: npx skills add https://github.com/ruiyangruiyi/hermes-agent --skill instructor-ruiyangruiyi

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires instructor, pydantic, openai, anthropic, and includes references (resource) components.

What problem does it solve?

Instructor solves the reliability gap in structured extraction, where raw LLM responses often produce invalid JSON or missing fields, making downstream processing brittle and error-prone.

Core Features & Use Cases

  • Pydantic-validated structured outputs: enforce schemas with type safety for extracted fields and nested objects.
  • Automatic retry on validation failures: re-asks the model with validation error context when outputs don’t conform.
  • Streaming partial results: incrementally consume in-progress structured generations for responsive apps.
  • Multi-provider support: use the same response modeling pattern across OpenAI and Anthropic (and compatible setups).

Quick Start

Extract a well-formed JSON object from a model response and validate it against your Pydantic schema with Instructor so retries happen automatically when fields are invalid or missing.

Frequently Asked Questions about instructor

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I extract structured JSON data from LLM responses and validate it against a schema?

To extract structured JSON data from LLM responses, you can use the Instructor library to validate outputs against Pydantic schemas, ensuring type safety and consistent formatting for reliable downstream processing even when raw model outputs are messy.

Why does my LLM output return invalid JSON or missing fields during data extraction?

LLM output often returns invalid JSON or missing fields due to the model's non-deterministic nature. Using Instructor introduces automatic retry behavior, re-asking the model with validation error context until the data extraction conforms strictly to your schema.

Can I use Pydantic structured outputs with both OpenAI and Anthropic models?

Yes, you can use Pydantic structured outputs with both OpenAI and Anthropic. Instructor provides multi-provider support, allowing you to apply the same response modeling pattern and schema validation across different LLM providers seamlessly.

What is the best way to stream partial JSON objects from an LLM for responsive applications?

The best way to stream partial JSON objects from an LLM is by using Instructor's streaming feature, which allows you to incrementally consume in-progress structured generations as they are produced, enabling more responsive application interfaces.

How do I enforce type safety and schema validation for multi-entity LLM classification tasks?

To enforce type safety for multi-entity LLM classification tasks, Instructor validates extracted data against Pydantic schemas, constraining outputs to typed and consistent formats while automatically retrying on any validation failures.

Does Instructor handle nested objects and complex JSON parsing from language models?

Yes, Instructor handles complex JSON parsing from language models by enforcing schemas with type safety for extracted fields and nested objects, ensuring that deeply structured data is correctly validated and ready for downstream use.