# AI use cases for Instructor (567-labs/instructor)

Repo: [567-labs/instructor](https://github.com/567-labs/instructor) | Use cases: 3 | Page: https://dedupedai.com/use-cases/567-labs-instructor/

Instructor gets reliable structured JSON out of LLMs. You define a Pydantic model, call `instructor.from_provider` with any major provider such as OpenAI, Anthropic, Google, Groq or local Ollama, and get back a validated, typed object, with automatic retries when validation fails.

This file holds every use case of this repo. Each one starts with a "## " heading and ends with its URL.

- Turn free text into a validated Pydantic object: https://dedupedai.com/use-cases/567-labs-instructor/extract-structured-data-from-text-with-instructor/
- Run the same extraction on OpenAI, Anthropic or local Ollama: https://dedupedai.com/use-cases/567-labs-instructor/switch-llm-providers-with-instructor-from-provider/
- Retry automatically when the LLM output fails validation: https://dedupedai.com/use-cases/567-labs-instructor/auto-retry-failed-llm-validations-with-instructor/

## How to turn free text into a validated Pydantic object with Instructor

Repo: [567-labs/instructor](https://github.com/567-labs/instructor) | Difficulty: Beginner | Time: 15 minutes | Basis: From the README

Define a model like User with name and age and let Instructor fill it from natural language.

**Who it is for:** A backend developer parsing names, dates or amounts out of messages.

**The problem:** Hand-written JSON schemas and parsing code break often.

**The outcome:** A typed, validated object instead of a raw string.

### Steps

1. Install with `pip install instructor`
2. Define a Pydantic BaseModel with the fields you want
3. Create a client with Instructor.from_provider("openai/gpt-4o-mini")
4. Call client.chat.completions.create with response_model set to your model and print the result

### Prompt to paste into your agent

```text
Using 567-labs/instructor, install `pip install instructor`, define a Pydantic model for <the fields I need>, and write a function that extracts it from a list of support emails with client.chat.completions.create and response_model.
```

### Caveat

This card is written from the 567-labs/instructor README, not from a test run by Deduped. Before you start, make sure you have Python with pip, uv or poetry. Check the repo for newer instructions before you rely on these steps.

Risk, cost: Each extraction is a paid LLM call unless you use a local model.

Disclaimer: Third-party repos we don't own or vouch for. AI-generated use cases can be wrong: review everything and run at your own risk. Full text: https://dedupedai.com/disclaimer/

URL: https://dedupedai.com/use-cases/567-labs-instructor/extract-structured-data-from-text-with-instructor/

## How to run the same extraction on OpenAI, Anthropic or local Ollama with Instructor

Repo: [567-labs/instructor](https://github.com/567-labs/instructor) | Difficulty: Intermediate | Time: 30 minutes | Basis: From the README

Swap providers by changing one string in from_provider while the rest of the code stays the same.

**Who it is for:** A team comparing providers on cost and quality, or moving to a local model.

**The problem:** Every provider has a different API shape for structured output.

**The outcome:** One extraction function that runs on several providers.

### Steps

1. Install with `uv add instructor` or `poetry add instructor`
2. Create clients like Instructor.from_provider("ollama/llama3.2") or Instructor.from_provider("openai/gpt-4o")
3. Call the same client.chat.completions.create with your response_model on each
4. Compare accuracy and cost across providers

### Prompt to paste into your agent

```text
With 567-labs/instructor, write a script that runs one extraction on instructor.from_provider("openai/gpt-4o") and instructor.from_provider("ollama/llama3.2") over <my 20 samples>, and reports where they disagree.
```

### Caveat

This card is written from the 567-labs/instructor README, not from a test run by Deduped. Before you start, make sure you have Python with pip, uv or poetry. Check the repo for newer instructions before you rely on these steps.

Risk, credentials: Passing api_key directly is supported, but keep keys in environment variables, not in code.

Disclaimer: Third-party repos we don't own or vouch for. AI-generated use cases can be wrong: review everything and run at your own risk. Full text: https://dedupedai.com/disclaimer/

URL: https://dedupedai.com/use-cases/567-labs-instructor/switch-llm-providers-with-instructor-from-provider/

## How to retry automatically when the LLM output fails validation with Instructor

Repo: [567-labs/instructor](https://github.com/567-labs/instructor) | Difficulty: Intermediate | Time: 20 minutes | Basis: From the README

Add Pydantic field validators and let Instructor resend the error to the model until the data is valid.

**Who it is for:** A developer whose pipeline breaks on the occasional malformed answer.

**The problem:** Invalid LLM output means manual retries and error handling code.

**The outcome:** Data that passes your validators, with retries handled for you.

### Steps

1. Install with `pip install instructor`
2. Add a field_validator to your Pydantic model, for example on age
3. Call client.chat.completions.create with response_model as usual
4. Failed validations are retried with the error message, per the Automatic retries section

### Prompt to paste into your agent

```text
Using 567-labs/instructor, add Pydantic field_validator rules for <my business rules> to my model and show how Instructor's automatic retries handle an input that fails them the first time.
```

### Caveat

For agents with observability and traces, the README itself points to PydanticAI.

Risk, cost: Each retry is another LLM call.

Disclaimer: Third-party repos we don't own or vouch for. AI-generated use cases can be wrong: review everything and run at your own risk. Full text: https://dedupedai.com/disclaimer/

URL: https://dedupedai.com/use-cases/567-labs-instructor/auto-retry-failed-llm-validations-with-instructor/
