HackerReposA FIELD GUIDE TO OPEN SOURCE
ProSponsor the shelf♧ 0
← Back to top all-time
newhouseb
clownfish
Python2023–2023
newhouseb / clownfish

clownfish

Constrained Decoding for LLMs against JSON Schema

9Distinct people
20Mentions
0Explicit recommenders
328GitHub stars
REPOSITORY AT A GLANCE

What to know before exploring

What it is

Constrained Decoding for LLMs against JSON Schema

GitHub

Where it is used

No documented product use has been verified yet.

What people are saying

No recommendation phrase was found in the indexed comments.

No classified warning is attached to this page. Read the discussions before treating silence as approval.

Also in these discussions

Mentioned in the same Hacker News threads. That is not proof they are substitutes.

This week on Hacker News

Nov 7–Nov 14 UTC · Direct repository links and separately labeled related project stories. Indexed through 11/14/2026, 5:04:57 PM UTC.

No direct repository links were found in the indexed HN discussions over the past seven days. Older discussions are available below.

Mentions over time

HN mentions by week20 dated mentions

Observed mentions: 2023-03-27 12:03:16 UTC to 2023-08-14 20:35:04 UTC. Weeks start Monday, UTC.

012342023-03-27 00:00:00 UTC to 2023-04-03 00:00:00 UTC (exclusive): 4 mentions; 2 submissions, 2 commentsMar 272023-04-03 00:00:00 UTC to 2023-04-10 00:00:00 UTC (exclusive): 1 mentions; 0 submissions, 1 comments2023-04-10 00:00:00 UTC to 2023-04-17 00:00:00 UTC (exclusive): 2 mentions; 0 submissions, 2 comments2023-04-17 00:00:00 UTC to 2023-04-24 00:00:00 UTC (exclusive): 1 mentions; 0 submissions, 1 comments2023-04-24 00:00:00 UTC to 2023-05-01 00:00:00 UTC (exclusive): 1 mentions; 0 submissions, 1 comments2023-05-01 00:00:00 UTC to 2023-05-08 00:00:00 UTC (exclusive): 3 mentions; 1 submissions, 2 comments2023-05-08 00:00:00 UTC to 2023-05-15 00:00:00 UTC (exclusive): 1 mentions; 0 submissions, 1 comments2023-05-15 00:00:00 UTC to 2023-05-22 00:00:00 UTC (exclusive): 3 mentions; 0 submissions, 3 comments2023-05-22 00:00:00 UTC to 2023-05-29 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2023-05-29 00:00:00 UTC to 2023-06-05 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2023-06-05 00:00:00 UTC to 2023-06-12 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 commentsJun 52023-06-12 00:00:00 UTC to 2023-06-19 00:00:00 UTC (exclusive): 2 mentions; 0 submissions, 2 comments2023-06-19 00:00:00 UTC to 2023-06-26 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2023-06-26 00:00:00 UTC to 2023-07-03 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2023-07-03 00:00:00 UTC to 2023-07-10 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2023-07-10 00:00:00 UTC to 2023-07-17 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2023-07-17 00:00:00 UTC to 2023-07-24 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2023-07-24 00:00:00 UTC to 2023-07-31 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2023-07-31 00:00:00 UTC to 2023-08-07 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2023-08-07 00:00:00 UTC to 2023-08-14 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2023-08-14 00:00:00 UTC to 2023-08-21 00:00:00 UTC (exclusive): 2 mentions; 0 submissions, 2 commentsAug 14

Counts come from the repository’s dated source evidence. Index cutoff: 2026-11-02 08:16:59 UTC.

View mention counts and date ranges
UTC ranges include their start and exclude their end. Select a period to filter the source evidence.
PeriodStart (UTC)End (exclusive, UTC)MentionsSubmissionsComments
Mar 272023-03-27 00:00:00 UTC2023-04-03 00:00:00 UTC422
Apr 32023-04-03 00:00:00 UTC2023-04-10 00:00:00 UTC101
Apr 102023-04-10 00:00:00 UTC2023-04-17 00:00:00 UTC202
Apr 172023-04-17 00:00:00 UTC2023-04-24 00:00:00 UTC101
Apr 242023-04-24 00:00:00 UTC2023-05-01 00:00:00 UTC101
May 12023-05-01 00:00:00 UTC2023-05-08 00:00:00 UTC312
May 82023-05-08 00:00:00 UTC2023-05-15 00:00:00 UTC101
May 152023-05-15 00:00:00 UTC2023-05-22 00:00:00 UTC303
May 222023-05-22 00:00:00 UTC2023-05-29 00:00:00 UTC000
May 292023-05-29 00:00:00 UTC2023-06-05 00:00:00 UTC000
Jun 52023-06-05 00:00:00 UTC2023-06-12 00:00:00 UTC000
Jun 122023-06-12 00:00:00 UTC2023-06-19 00:00:00 UTC202
Jun 192023-06-19 00:00:00 UTC2023-06-26 00:00:00 UTC000
Jun 262023-06-26 00:00:00 UTC2023-07-03 00:00:00 UTC000
Jul 32023-07-03 00:00:00 UTC2023-07-10 00:00:00 UTC000
Jul 102023-07-10 00:00:00 UTC2023-07-17 00:00:00 UTC000
Jul 172023-07-17 00:00:00 UTC2023-07-24 00:00:00 UTC000
Jul 242023-07-24 00:00:00 UTC2023-07-31 00:00:00 UTC000
Jul 312023-07-31 00:00:00 UTC2023-08-07 00:00:00 UTC000
Aug 72023-08-07 00:00:00 UTC2023-08-14 00:00:00 UTC000
Aug 142023-08-14 00:00:00 UTC2023-08-21 00:00:00 UTC202

What Hacker News says

20 sources
I'm not sure how this is different than: https://github.com/1rgs/jsonformer or https://github.com/newhouseb/clownfish or https://github.com/mkuchnik/relm or https://github.com/ggerganov/llama.cpp/pull/1773 or https://github.com/Shopify/torch-grammar Overall there are a ton of these logit based guidance systems, the reason they don't get tons of traction is the SOTA models are behind REST APIs that don't enable this fine-grained approach. Those models perform so much better that people generally settle for just re-requesting until they get the correct format (and with GPT-4 that ends up being a fairly rare occurrence in my experience)
In Show HN: LLMs can generate valid JSON 100% of the time
As someone also building constrained decoders against JSON [1], I was hopeful to see the same but I note the following from their documentation: The model can choose to call a function; if so, the content will be a stringified JSON object adhering to your custom schema (note: the model may generate invalid JSON or hallucinate parameters). So sadly, it is just fine tuning. There's no hard biasing applied :(. You were so close, but so far OpenAI! [1] https://github.com/newhouseb/clownfish [2] https://platform.openai.com/docs/guides/gpt/function-calling
In Function calling and other API updates
The interface makes it look simple, but under the hood it follows a similar approach to jsonformer/clownfish [1] passing control of generation back and forth between a slow LLM and relatively fast python Let's say you're halfway through a generation of a json blob with a name field and a job field and have already generated { "name": "bob" At this point, guidance will take over generation control from the model to generate the next text { "name": "bob", "job": If the model had generated that, you'd be waiting 70 ms per token (informal benchmark on my M2 air). A comma, followed by a newline, followed by "job": is 6 tokens, or 420ms. But since guidance took over, you save all that time. Then guidance passes control back to the model for generating the next field value. { "name": "bob", "job": "programmer" progra
Read the rest
mmer is 2 tokens and the closing " is 1 token, so this took 210ms to generate. Guidance then takes over again to finish the blob { "name": "bob", "job": "programmer" } [1] https://github.com/1rgs/jsonformer https://github.com/newhouseb/clownfish Note: guidance is way more general of a tool than these Edit: spacing
In A guidance language for controlling LLMs
Oh nice! I built a similar system a few weeks ago: https://github.com/newhouseb/clownfish I think the main differentiating factor here is that this is better if you have a simpler JSON schema without enums or oneOf constraints. If you do have these constraints, i.e. let's say you wanted an array of different types that represented a items on a menu { kind: pizza, toppings: [pepperoni] } or { kind: ice_cream, flavor: vanilla | strawberry } then you would need something more sophisticated like clownfish that can ask the LLM to pick specific properties (and an ability to do some backtracking so you can do proper beam search). For completeness, another common approach can be found here: https://github.com/ShreyaR/guardrails which essentially boils down to "provide the schema in the prompt and ask the LLM to correct things if it fails to get t
Read the rest
he schema right the first time."
In Jsonformer: Generate structured output from LLMs
There are a couple different approaches: - Use multi-shot prompting with something like guardrails to try prompting a commercial model until it works. [1] - Use a local model with a final layer that steers token selection towards syntactically valid tokens [2] [1] https://github.com/ShreyaR/guardrails [2] "Structural Alignment: Modifying Transformers (like GPT) to Follow a JSON Schema" @ https://github.com/newhouseb/clownfish (full disclosure: this is my work)
In Ask HN: AI to study my DSL and then output it?

Showing the 15 most recent of 20 sources. Enable JavaScript to search and browse every indexed mention.

MAKE YOURSELF AT HOME

A few shortcuts

/
Search the collection
?
Open this guide
Esc
Close dialogs and navigation

Your saved repositories and interests stay in this browser.