instructor

Extract structured data from LLM outputs using Pydantic schemas.

Updated Aug 23, 2026
One-click install
npx skills add https://github.com/box755/simlens-research --skill instructor-box755
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: instructor
Source: https://github.com/box755/simlens-research/tree/main/skill-packs/AI-Research-SKILLs/16-prompt-engineering/instructor
Command: npx skills add https://github.com/box755/simlens-research --skill instructor-box755

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve?

Instructor helps you reliably extract structured information from LLM responses while enforcing a schema, catching invalid outputs early, and automatically retrying until the result conforms to your Pydantic model.

Core Features & Use Cases

  • Validated structured outputs with Pydantic: Define a response model (types, constraints, enums, nested objects) and have Instructor validate the model output for you.
  • Automatic retries on validation failures: When extraction fails (missing fields, invalid formats, constraint violations), Instructor feeds validation errors back to the LLM and retries.
  • Robust parsing for complex JSON and typing: Safely handle nested structures, optional fields, and strict constraints so downstream code can trust the result.
  • Streaming partial results: Receive partial objects during generation to power responsive UIs or incremental pipelines.
  • Multi-provider support: Use consistent structured-output patterns across supported LLM providers (e.g., Anthropic and OpenAI).

Quick Start

Use the instructor skill to extract and validate a JSON object from an LLM by specifying your Pydantic model as the response_model for the request.

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 from LLM outputs and validate it with Pydantic?

To extract structured JSON from LLM outputs, define a Pydantic response model with your required types and constraints, then pass it as the response_model parameter. The LLM output is parsed and validated against your schema, returning a fully typed object.

Why does LLM structured data extraction fail validation and how can I fix it?

LLM structured data extraction fails validation when outputs miss fields or violate constraints. This is fixed by enabling automatic retries, which feed the specific Pydantic validation errors back to the LLM as context, prompting regeneration until the output conforms.

Can I stream partial JSON objects from an LLM during generation?

Yes, you can stream partial JSON objects from an LLM during generation. By enabling streaming, you receive partially constructed Pydantic objects incrementally as the LLM produces tokens, allowing you to power responsive UIs or incremental data pipelines.

Does this approach work with both OpenAI and Anthropic APIs for structured output?

Yes, this approach works with both OpenAI and Anthropic APIs for structured output. It provides consistent Pydantic validation and structured extraction patterns across multiple supported LLM providers, ensuring type safety regardless of the underlying API.

What is the best way to parse nested JSON structures and complex types from natural language?

The best way to parse nested JSON structures and complex types from natural language is using Pydantic schemas with automatic retries. This safely handles nested objects, optional fields, and strict constraints, ensuring downstream code can trust the validated result.

How do I enforce type safety when extracting multiple entities from LLM responses?

To enforce type safety when extracting multiple entities from LLM responses, define a Pydantic model containing nested objects, enums, and constraints. The extraction process validates the LLM output against this schema, automatically retrying with error feedback if validation fails.