instructor

Extract validated structured data from LLM responses into Pydantic models.

Updated Apr 9, 2026
One-click install
npx skills add https://github.com/MarbleSodas/Mavis --skill instructor-marblesodas
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: instructor
Source: https://github.com/MarbleSodas/Mavis/tree/main/optional-skills/mlops/instructor
Command: npx skills add https://github.com/MarbleSodas/Mavis --skill instructor-marblesodas

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve?

Extracting structured fields from LLM outputs is often brittle: JSON can be malformed, required fields can be missing, and types don’t reliably match what your app expects.

Core Features & Use Cases

  • Pydantic-validated structured outputs: Enforce schemas (types, constraints, enums) so you get reliable, typed data for downstream logic.
  • Automatic retry on validation failures: When extraction fails, the library feeds validation errors back to the model and re-attempts until it succeeds (configurable retries).
  • Safe, type-aware parsing for complex JSON: Handle nested models, optional fields, and constrained values with consistent structure.
  • Streaming partial results: Process incremental outputs in real time for faster UX and incremental pipelines.
  • Multi-provider support: Work across OpenAI and Anthropic with consistent response handling.

Quick Start

Use instructor to extract a Pydantic model from a messy LLM response, automatically retrying until the output matches your schema.

Frequently Asked Questions about instructor

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

FAQPage Schema
How do I extract structured data from LLM responses into Pydantic models?

Structured data extraction from LLM responses into Pydantic models is achieved by validating schemas, enforcing types and constraints, and feeding validation errors back to the model for automatic retries until the output matches.

Why does JSON parsing fail when extracting nested fields from LLM outputs?

JSON parsing fails when extracting nested fields because LLM outputs often contain malformed JSON, missing required fields, or mismatched types that do not align with your application's expected schema constraints.

Can I stream partial Pydantic model results from OpenAI and Anthropic responses?

Streaming partial Pydantic model results from OpenAI and Anthropic responses is supported, allowing you to process incremental structured outputs in real time for faster user experiences and incremental data pipelines.

What is the best way to automatically retry LLM data extraction on validation failure?

Automatically retrying LLM data extraction on validation failure is handled by feeding Pydantic validation errors back to the model and re-attempting extraction until it succeeds, with configurable retry limits.

Does instructor work with both OpenAI and Anthropic for structured output validation?

Structured output validation works with both OpenAI and Anthropic through provider-specific integrations, ensuring consistent response handling and Pydantic model enforcement across different LLM providers.

How do I enforce enums and constraints when parsing complex JSON from LLM text?

Enforcing enums and constraints when parsing complex JSON from LLM text is done by defining Pydantic models with specific types and rules, which the extraction process validates against before accepting the output.