zod-gpt  by dzhng

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

Created 2 years ago
625 stars

Top 52.9% 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

Inactive

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

Explore Similar Projects

Starred by John Resig John Resig(Author of jQuery; Chief Software Architect at Khan Academy), Jason Huggins Jason Huggins(Creator of Selenium), and
2 more.

instructor-js by 567-labs

0.3%
753
Typescript tool for structured extraction from LLMs
Created 1 year ago
Updated 7 months ago
Feedback? Help us improve.