Scripts2026年4月7日·1 分钟阅读

Instructor — Structured LLM Outputs with Pydantic

Extract structured data from LLMs using Pydantic models. Works with OpenAI, Anthropic, Gemini, and local models. The simplest way to get reliable JSON from any LLM.

What is Instructor?

Instructor patches LLM client libraries so they return validated Pydantic objects instead of raw text. Supports retries, streaming output, and partial responses.

In one sentence: Instructor extracts structured data from LLMs using Pydantic models, supporting OpenAI, Anthropic, Gemini, and local models.

Core Patterns

1. Multi-Provider Support

Works with OpenAI, Anthropic, Gemini, Ollama, and more — switch with a single line.

2. Nested Complex Types

Supports nested models, lists, optional fields, and the full power of Pydantic.

3. Streaming Partial Results

Fields fill in progressively — great for real-time display of large structured outputs.

4. Auto-Retry

On validation failure, automatically feeds the error back to the LLM for regeneration.

FAQ

Q: Does it support Claude? A: Yes, via instructor.from_anthropic() using tool-use mode.

Q: Performance overhead? A: Minimal — it's a thin wrapper. Retries add latency only on validation failure.

🙏

来源与感谢

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产