prompt-engineering-instructor — Claude Code skill: structured LLM
Shows your agent how to pull typed data out of model responses with Instructor and Pydantic, retries included.
npx claude-code-templates@latest --skill ai-research/prompt-engineering-instructorWhat prompt-engineering-instructor does
The skill covers Instructor, a library that turns a model reply into a Python object instead of a blob of text. You define a Pydantic model — fields, types, constraints — and pass it as response_model. When the output does not match, Pydantic raises, Instructor sends the error back to the model and asks for another attempt. Three retries is the default.
Inside you get nested models, optional fields with defaults, enums for fixed value sets, built-in and custom validators, and checks that run across the whole model. Both Anthropic and OpenAI are covered: build the client with instructor.from_anthropic(Anthropic()) or instructor.from_openai(OpenAI()), then call as usual.
Worth installing if you write extraction, JSON parsing or any pipeline that reads LLM answers. It will not run without a provider key and the packages named as dependencies: instructor, pydantic, openai, anthropic. Base install is pip install instructor; provider extras look like instructor[anthropic].
What it helps with
- pull named fields out of a free-form model reply
- check an LLM answer against a schema before it hits the database
- retry extraction when the model returns the wrong type
- parse nested JSON without hand-written checks
- receive a partial object while generation is still running
Example prompts for the agent
- Write a Pydantic model that extracts name, age and email from text and show the call through instructor.from_anthropic
- Add a validator that enforces the YYYY-MM-DD date format and explain how Instructor retries on failure
- Build a nested Person model with an Address and print the city via person.address.city
How to install prompt-engineering-instructor
1claude-code-templates
npx claude-code-templates@latest --skill ai-research/prompt-engineering-instructor2Skills CLI (Vercel)
npx skills add davila7/claude-code-templates --skill prompt-engineering-instructor -a claude-code3Manually: put the files in place
~/.claude/skills/prompt-engineering-instructor/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/prompt-engineering-instructor/
Manually: put the files in place
.agents/skills/prompt-engineering-instructor/SKILL.mdFor all projects use ~/.agents/skills/
Manually: put the files in place
.cursor/skills/prompt-engineering-instructor/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install davila7/claude-code-templates prompt-engineering-instructor2Manually: put the files in place
.github/skills/prompt-engineering-instructor/SKILL.mdPlatform CLI
gemini skills install https://github.com/davila7/claude-code-templates --path cli-tool/components/skills/ai-research/prompt-engineering-instructorManually: put the files in place
.devin/skills/prompt-engineering-instructor/SKILL.mdThe legacy .windsurf/skills/ path still works
Claude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
Step by step, with commands for each platform: How to install skills in Claude Code: five ways
Questions about prompt-engineering-instructor
How do I install prompt-engineering-instructor in Claude?
Use the templates CLI: npx claude-code-templates@latest --skill ai-research/prompt-engineering-instructor. Or run npx skills add davila7/claude-code-templates --skill prompt-engineering-instructor -a claude-code. The skill file then sits at ~/.claude/skills/prompt-engineering-instructor/SKILL.md.
What does prompt-engineering-instructor do?
It documents how to get structured data back from an LLM with Instructor and Pydantic: response schemas, validation, automatic retries and streaming of partial results.
What do I need for this skill to work?
The instructor, pydantic, openai and anthropic packages, plus an API key for whichever provider you call. The examples build a separate client for Anthropic and for OpenAI.