strictjson  by tanchongmin

Structured output framework for LLM outputs

created 2 years ago
361 stars

Top 78.8% on sourcepulse

GitHubView on GitHub
Project Summary

StrictJSON is a Python framework designed to enforce structured output from Large Language Models (LLMs), primarily by parsing responses as YAML and validating them against Pydantic schemas. It supports a wide range of data types and offers LLM-based error correction for up to three retries, aiming to streamline LLM interactions for developers and researchers.

How It Works

The core innovation is the parse_yaml function, which treats LLM output as YAML. This approach leverages YAML's conciseness and better handling of code blocks compared to JSON. The framework automatically converts a user-defined output_format into a Pydantic schema, which is then used for validation. This allows for robust data type checking and error correction, ensuring the LLM's output conforms to the desired structure.

Quick Start & Requirements

  • Install via pip: pip install strictjson
  • Requires Python 3.7+
  • Supports various LLMs including OpenAI, Claude, and Llama models.
  • Tutorials available: parse_yaml.ipynb, strict_json.ipynb

Highlighted Details

  • Supports complex nested data structures (lists, dictionaries, unions, optionals).
  • Offers type forcing with LLM-based error correction (e.g., type: int, type: ensure <requirement>).
  • Integrates with OpenAI's JSON Mode.
  • Provides asynchronous processing capabilities (strict_json_async).

Maintenance & Community

  • Project initiated on April 7, 2023.
  • Open to collaborators.
  • Discussion channel available via Discord: discord.gg/bzp87AHJy5.
  • Related project: AgentJo (Agentic Framework).

Licensing & Compatibility

  • License: MIT.
  • Compatible with commercial use and closed-source applications.

Limitations & Caveats

The README notes that smaller versions of Llama 3.2 and 3.1 models may not work well with YAML parsing. Type checking is not supported when using OpenAI JSON Mode.

Health Check
Last commit

2 months ago

Responsiveness

1 day

Pull Requests (30d)
0
Issues (30d)
0
Star History
15 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
Feedback? Help us improve.