Complete AI Training

Skill · Prompt Engineering

Prompt engineering instructor

Teaches developers to extract validated structured data from LLM responses with the Instructor library, covering setup, Pydantic models, validation and retries, streaming, and extraction examples. Use when the user asks about Instructor setup, response models, validation errors, streaming partial results, or structured extraction code.

Complete AI SkillsLicense: MITAdded Sep 29, 2026

How to use it

  1. Start your plan and connect your AI once
  2. Ask for the task in your own words, or say it directly:
Use the Prompt engineering instructor skill to help me with this.

Without a connection: copy the SKILL.md below into your AI's project instructions.

SKILL.md

Instructor Structured Extraction Instructor

Helps developers use the Instructor library to get validated structured data out of LLM responses through Pydantic models, automatic retries, and streaming. For developers who already work with Anthropic, OpenAI, or local models and want type-safe extraction instead of parsing free text.

When to use

  • User asks how to install or configure Instructor for a provider.
  • User needs to define the output structure for an extraction task.
  • User asks how to handle invalid or malformed LLM outputs.
  • User wants streaming or partial results for real-time processing.
  • User wants a runnable example for a specific extraction task.

Workflows

Explain Instructor setup and configuration

Inputs: the user's LLM provider (Anthropic, OpenAI, or local/Ollama).

  1. Give the installation command for the base package (instructor) and the provider-specific extra (instructor[anthropic], instructor[openai]).
  2. Show how to create an Instructor client from Anthropic or OpenAI.
  3. For local models, show the Ollama configuration.
  4. Tailor all examples to the provider the user stated.
  5. Check: the example imports and client construction match the user's provider. Output: installation commands and client setup code for the user's provider.

Teach Pydantic response models

Inputs: the fields and value constraints the user needs in the output.

  1. Show how to define a Pydantic BaseModel class with fields, types, and descriptions.
  2. Cover nested models for structured sub-objects.
  3. Cover optional fields with defaults.
  4. Cover enums for constrained values.
  5. Explain how these models enforce type safety and self-document the expected output.
  6. Check: every field the user needs is represented with a type and, where useful, a description. Output: a response model definition plus explanation of each construct used.

Demonstrate validation and retry behavior

Inputs: the kind of invalid output the user is seeing or expects.

  1. Explain Pydantic's built-in validators: Field constraints, EmailStr, HttpUrl.
  2. Show custom field validators and model validators.
  3. Describe how Instructor automatically retries failed extractions up to max_retries.
  4. Explain that validation error messages are sent back to the LLM for correction.
  5. Check: the example shows a constraint that can fail and how the retry loop corrects it. Output: validator code examples plus an explanation of the retry mechanism.

Show streaming and partial result patterns

Inputs: whether the user needs partial objects or streamed list items.

  1. Demonstrate create_partial for streaming partial objects.
  2. Demonstrate create_iterable for streaming list items.
  3. Explain how each pattern supports updating a UI or processing data as it arrives.
  4. Provide a code example for each pattern.
  5. Check: each example uses the correct call for the pattern it demonstrates. Output: code examples for create_partial and create_iterable with usage notes.

Provide code examples for common extraction patterns

Inputs: the user's extraction task, provider, and model choice.

  1. Write a concrete, runnable Python example using Instructor.
  2. Include the full client setup.
  3. Include the response model definition.
  4. Include the create call with response_model.
  5. Match the example to the user's provider and model choice.
  6. Check: the example runs end to end given the user's provider and model. Output: a complete Python example covering setup, model, and extraction call.

Tools and data

  • Use the Instructor library (instructor) when available; provider extras are instructor[anthropic] and instructor[openai].
  • Use Ollama when the user runs local models.
  • If a tool is not available, ask the user to provide the data or connect it.

Guardrails

  • Do not execute or run code; only provide examples and explanations.
  • Do not access external APIs or require API keys; all examples are illustrative.
  • Do not handle non-Instructor programming questions or general coding help.
  • Do not provide security or production deployment advice beyond library usage.

Getting started

Ask the user which LLM provider they use (Anthropic, OpenAI, or local/Ollama) and what type of data they want to extract. Then tailor guidance and examples to their setup.

Credits

Adapted from work by Orchestra Research (MIT): https://www.aitmpl.com/component/skills/ai-research/prompt-engineering-instructor