zod-gpt  by dzhng

SDK for structured JSON output from LLMs, validated via Zod schemas

created 2 years ago
626 stars

Top 53.7% on sourcepulse

GitHubView on GitHub
Project Summary

ZodGPT provides a library for obtaining structured, fully typed, and validated JSON outputs from OpenAI and Anthropic language models. It targets developers building applications that require reliable data extraction from LLMs, ensuring type safety and data integrity through Zod schema validation and automatic output correction.

How It Works

ZodGPT leverages the LLM's function calling capabilities to coerce responses into a structured format. It integrates with the Zod library for schema definition, serialization, and parsing. A key feature is "auto-healing," where the library automatically prompts the LLM to correct its own output if it deviates from the expected schema or function call format, enhancing reliability.

Quick Start & Requirements

  • Install via npm: npm i zod-gpt or yarn: yarn add zod-gpt.
  • Requires a peer dependency on llm-api for LLM provider integration.
  • Example usage involves importing completion from zod-gpt and an LLM API client (e.g., OpenAIChatApi) from llm-api.
  • Official documentation and examples are available within the README.

Highlighted Details

  • Enforces type safety and validation using Zod schemas.
  • Supports automatic output correction ("auto-healing") via self-reflection.
  • Includes an autoSlice option to handle token limit issues by splitting prompts.
  • Gracefully handles API errors like rate limiting with exponential backoff.

Maintenance & Community

The project appears to be maintained by a single author, dzhng. There are no explicit mentions of community channels (like Discord/Slack) or a public roadmap in the README.

Licensing & Compatibility

The README does not explicitly state a license. This requires further investigation to determine compatibility for commercial use or closed-source linking.

Limitations & Caveats

The schema option currently only accepts object type schemas due to limitations of the function calling API; other types must be wrapped in an object. The contextSize must be explicitly set in llm-api options to enable token overflow error detection for autoSlice.

Health Check
Last commit

1 year ago

Responsiveness

1+ week

Pull Requests (30d)
0
Issues (30d)
0
Star History
4 stars in the last 90 days

Explore Similar Projects

Starred by John Resig John Resig(Author of jQuery; Chief Software Architect at Khan Academy), Travis Fischer Travis Fischer(Founder of Agentic), and
1 more.

instructor-js by 567-labs

0%
738
Typescript tool for structured extraction from LLMs
created 1 year ago
updated 6 months ago
Starred by Chip Huyen Chip Huyen(Author of AI Engineering, Designing Machine Learning Systems), Andreas Jansson Andreas Jansson(Cofounder of Replicate), and
1 more.

lm-format-enforcer by noamgat

0.2%
2k
Format enforcer for language model outputs (JSON, regex, etc.)
created 1 year ago
updated 5 months ago
Feedback? Help us improve.