Typescript tool for structured extraction from LLMs
Top 47.9% on sourcepulse
This library provides structured data extraction from Large Language Models (LLMs) using TypeScript, OpenAI's function calling API, and Zod for schema validation. It's designed for developers needing to reliably parse LLM outputs into typed data structures, offering simplicity, transparency, and control over the extraction process.
How It Works
Instructor extends the OpenAI SDK client, enabling structured extraction by leveraging Zod schemas. It supports multiple modes (TOOLS, JSON, MD_JSON, JSON_SCHEMA) to guide LLM output formatting. The core mechanism involves passing a Zod schema to the response_model
parameter in chat.completions.create
, allowing the LLM to generate output that conforms to the defined structure, which is then validated and parsed by Zod.
Quick Start & Requirements
bun add @instructor-ai/instructor zod openai
, npm i @instructor-ai/instructor zod openai
, or pnpm add @instructor-ai/instructor zod openai
.Highlighted Details
llm-polyglot
.zod-stream
, schema-stream
, llm-polyglot
.Maintenance & Community
Licensing & Compatibility
Limitations & Caveats
The library relies on LLM providers correctly implementing OpenAI's API specifications for seamless integration. Specific model capabilities and adherence to tool/function calling formats can influence extraction accuracy.
6 months ago
Inactive