GPT-JSON: Structured and typehinted GPT responses in Python

This page summarizes the projects mentioned and recommended in the original post on

Our great sponsors
  • Mergify - Updating dependencies is time-consuming.
  • Sonar - Write Clean Python Code. Always.
  • InfluxDB - Collect and Analyze Billions of Data Points in Real Time
  • jsonformer

    A Bulletproof Way to Generate Structured JSON from Language Models

    Hey HN, I've been using GPT in some side projects mostly around data generation and benchmarking. During the course of prompt tuning I ended up with a complicated request: the value that I was looking for, an explanation, a criticism, etc. JSON was the most natural output format for this but results would often be broken, have wrong types, or contain missing fields.

    There's been some positive movement in this space, like with [jsonformer]( the other day. But nothing that was plug and play with GPT.

    This library consolidates the separate logic that I built across 5 different projects. It lets you hint the model for how it should return fields, variable inject prompts, handle common formatting errors, then cast to pydantic when you're done for typehinting and validation in your IDE. If you're able to play around with it, let me know what you think.

  • pydantic-chatcompletion

    Wraps openai.ChatCompletion to produce pydantic model output via schema prompt and error feedback.

    Nice project! I took some inspiration from this as well as to create the following:

    I tried to make the API as intuitive as possible and added the ability to provide examples to improve the reliability and quality of the LLM's output.

  • Mergify

    Updating dependencies is time-consuming.. Solutions like Dependabot or Renovate update but don't merge dependencies. You need to do it manually while it could be fully automated! Add a Merge Queue to your workflow and stop caring about PR management & merging. Try Mergify for free.

  • struct-gpt

    get structured output from LLM's

    Nice project! I took some inspiration from this as well as to create the following:

    I tried to make the API as intuitive as possible and added the ability to provide examples to improve the reliability and quality of the LLM's output.

  • gpt-json

    Structured and typehinted GPT responses in Python

  • gpt-logic

    Translate the natural language generated by OpenAI's GPT models or any other large language models into JavaScript data types like booleans and objects.

    I happen to have a very similar idea recently and created this GPT-logic package for node. It basically transforms GPT generated results into JS data types. Check it out if you are interested.

  • zod-chatgpt

    I built zod-chatgpt a couple of weeks ago to serve same purpose in typescript

  • cue

    The home of the CUE language! Validate and define text-based and dynamic configuration

    I asked ChatGPT (GPT-4) about the idea of integrating GPT-JSON with CUE language ( for improvement and the answers are quite impressive:

    "Yes, integrating the CUE language with GPT-JSON can potentially lead to improvements in its capability. CUE, short for Configuration, Unification, and Environment, is an open-source data constraint language designed to simplify the definition, generation, and validation of data in structured formats, like JSON, YAML, and others.

    Integrating CUE with GPT-JSON can bring several benefits:

    1) Validation: By using CUE, you can define schemas for the input and output JSON, which helps in validating the data structure and ensuring it adheres to the expected format. This can help reduce errors and improve the quality of the interaction with the GPT model.

    2) Simplification: CUE can help simplify the process of defining and generating JSON inputs and outputs for GPT-JSON. By providing a more concise and expressive syntax, CUE can make it easier to craft structured inputs and outputs, which can be especially helpful when working with complex data structures.

    3) Interoperability: Integrating CUE can improve the interoperability between GPT-JSON and other systems or applications. With CUE's ability to work with multiple data formats (such as JSON, YAML, or HCL), it becomes easier to integrate GPT-JSON with various tools and platforms.

    To integrate CUE with GPT-JSON, you would need to follow these general steps:

    1) Define CUE schemas for the input and output JSON structures used by GPT-JSON.

  • Sonar

    Write Clean Python Code. Always.. Sonar helps you commit clean code every time. With over 225 unique rules to find Python bugs, code smells & vulnerabilities, Sonar finds the issues while you focus on the work.

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts