The archive · Product Ideas · Product decision · 2023
GPT-JSON makes Python type hints the schema for structured GPT output
A May 2023 Python wrapper turns Pydantic models into prompt schema, then parses GPT replies into typed objects and repairs broken JSON automatically.
GPT-JSON
What it had to solve
In spring 2023, developers who wanted JSON back from GPT had to coax it out with prose instructions and then clean the result: replies arrived truncated, used Python-style True/False instead of true/false, or came wrapped in extra text. Existing libraries (the GPT-JSON README names jsonformer) did not fit the author's OpenAI-based deployment, so he wrote his own wrapper.
How it works
In early 2023 the standard way to get structured data out of GPT was to ask nicely in prose and clean up whatever came back. Replies would arrive truncated mid-object, with Python-style True instead of JSON true, or wrapped in conversational text — and every developer who built on the API re-solved the same cleanup problem by hand.
GPT-JSON's move was to make the schema a type instead of a paragraph. The user defines the expected answer as a Pydantic BaseModel, puts a {json_schema} keyword in the prompt wherever it fits, and the library injects the model's schema at runtime. The response is parsed straight into a typehinted object, with lightweight transformations that re-close truncated JSON and correct boolean literals, plus retry logic for common API failures.
Launched as a Show HN on 4 May 2023, the project drew 174 points and 72 comments. Developers compared its retry loop with pydantic-chatcompletion and jsonformer, argued over typed ChatGPT approaches, and shared schema-templating tricks. The repository later reached 734 stars before the owner archived it as read-only in June 2025, as structured-output tooling became a standard layer of the LLM stack.
Why it lands
- The schema was already in the code: a Pydantic model is both the validator and the prompt, so the contract cannot drift from what the program actually expects.
- Prompt position mattered less than the injection itself — the {json_schema} keyword could sit in the system or user prompt, making the library flexible without extra configuration.
- Treating broken output as a fixable case, not a failure, turned truncation and boolean typos into transformations the caller could audit and even reject.
- Launching as open source on Hacker News surfaced the competing approaches early, letting the author position the library against the ecosystem instead of guessing.
What it did
The Show HN on 4 May 2023 drew 174 points and 72 comments, where developers swapped retry and schema tricks and compared pydantic-chatcompletion, jsonformer and Guardrails. The repository shows 734 stars, and the owner archived it as read-only on 12 June 2025.
What you can take
When an AI model's output format is the real API, encode it in the type system instead of prose: schema injection, validation and repair become code that runs every time, not prompt folklore.
Since then
The launch thread read like a design review: commenters shared pydantic-chatcompletion alternatives, suggested YAML parsing for capital booleans, and debated whether retrying with validation errors was wise. The author kept the library focused on OpenAI GPT models, explicitly contrasting it with jsonformer's Hugging Face approach. By June 2025, when the owner archived the repository, structured outputs had become a standard layer of LLM tooling and the niche GPT-JSON filled had been absorbed by the platforms it wrapped.
Sources
- Show HN: GPT-JSON – Structured and typehinted GPT responses in Python
- piercefreeman/gpt-json — Structured and typehinted GPT responses in Python
spotted an error? The archive wants to know.
Your turn
You just read one. Describe the brief you are staring at, and see who has been given the same problem.
Free account · 3 free questions · no card