News for hackers. Stuff that matters.
Re:Jsonformer: A bulletproof way to generate structured outp... by newhouseb on Tuesday May 02, 2023 @02:48PM (#35792347)
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 the schema right the first time."

Re:Jsonformer: A bulletproof way to generate structured outp... by gamegoblin on Tuesday May 02, 2023 @03:13PM (#35792659)
I hate that gpt-3.5-turbo is so cheap that using systems like guardrails is a sane thing to do. I can almost always prompt davinci-003 without guardrails in a way to get my exact schema 1-shot, whereas guardrails + 3.5-turbo will often consume 2-4x more tokens, but that still makes it significantly cheaper.
Re:Jsonformer: A bulletproof way to generate structured outp... by brigadier132 on Tuesday May 02, 2023 @04:41PM (#35793879)
The problem people are having is hitting the rate limits for chat gpt.
Re:Jsonformer: A bulletproof way to generate structured outp... by selcuka on Wednesday May 03, 2023 @08:43PM (#35809841)
Is there a rate limit for the paid API [1] too?

[1] https://platform.openai.com/docs/models/gpt-3-5

Re:Jsonformer: A bulletproof way to generate structured outp... by gamegoblin on Thursday May 04, 2023 @06:14PM (#35822864)
You will get rate limit errors on all the models if you push hard enough. I always wrap the API with some exponential backoff retries to work around this.
Re:Jsonformer: A bulletproof way to generate structured outp... by sudb on Tuesday May 02, 2023 @03:43PM (#35793079)
Another very similar approach to guardrails which manages to avoid XML that I've been using with some success is langchain's OutputFixingParser: https://python.langchain.com/en/latest/modules/prompts/outpu...
Re:Jsonformer: A bulletproof way to generate structured outp... by killthebuddha on Tuesday May 02, 2023 @05:14PM (#35794307)
One thing that I really like about the approach you took with clownfish is that it doesn't constrain or modify the structure of the prompt.

One of the primary difficulties with writing LLM applications is that prompts are basically not composable, and any LLM library that modifies your prompt is going to be a nightmare to work with.

Re:Jsonformer: A bulletproof way to generate structured outp... by killthebuddha on Tuesday May 02, 2023 @05:23PM (#35794407)
Follow-up thought I just had: It seems that prompt structure standards are going to have to emerge if any of these tools have a shot at interoperability. I don't have hard data, but IME if a prompt is structured

MEMORY EXAMPLE INSTRUCTION [COMPLETION]

it will basically not work to wrap it in a prompt that's structured

INSTRUCTION MEMORY EXAMPLE [COMPLETION]

Re:Jsonformer: A bulletproof way to generate structured outp... by ianbutler on Tuesday May 02, 2023 @05:39PM (#35794591)
* * *
Re:Jsonformer: A bulletproof way to generate structured outp... by killthebuddha on Tuesday May 02, 2023 @09:41PM (#35796660)
I think I agree, and am doing something similar as well. Even the adapters approach does require some amount of consistency across prompts. For example, if you have one prompt that says “you are a very helpful assistant” and one prompt that says “you are a very lazy assistant”, then even if those prompts are otherwise written to be as orthogonal as possible you will still probably see degradation in completion quality.
Re:Jsonformer: A bulletproof way to generate structured outp... by newhouseb on Tuesday May 02, 2023 @10:20PM (#35796954)
I haven't spent time going deep here but my current hypothesis is that interoperability will more or less end up looking like toolformer where the "tools" are just separate LLM runs with task-specific context. So for example:

> Instruction: Write a poem and them emit a structure that follows a schema named X.

> Completion: [map-schema X "roses are red, violets are blue"]

Conceptually this is basically just a function call where context is local to the function.

Re:Jsonformer: A bulletproof way to generate structured outp... by joshuanapoli on Tuesday May 02, 2023 @06:16PM (#35794966)
Thank you for the really clear and complete description of "ControLogit"s and your approach in clownfish!
Re:Jsonformer: A bulletproof way to generate structured outp... by gordian-not on Wednesday May 03, 2023 @02:04AM (#35798587)
I have stumbled upon your repository a week ago and I have to say, great work and great ideas!

Another thing I thought about is integrating formatting for fields using a similar system. ISO-8601 dates comes immediately to mind but also number and currency formatting are other examples.

Probabilistic enums is another thing that I can think of that might be useful for fallback values, I am pretty sure there's a lot of work that can be done in this area, also for other parser kinds

related and highly recommended resource is https://github.com/mkuchnik/relm and https://arxiv.org/abs/2211.15458. It is a similar system used to validate LLMs using regexes, however built for completely different use cases. I imagine integrating regex checks to the output fields can also have a lot of use cases.

Re:Jsonformer: A bulletproof way to generate structured outp... by newhouseb on Wednesday May 03, 2023 @08:53AM (#35801806)
Thank you! ReLM is a great find! I like that it drives the generation itself so that it can explore different beams more intentionally. And to do the JSON Parsing well against enums/unions/oneOf, you really have to support backtracking in a way that works basically the same as it does for regex so I'm looking forward to digging into their implementation.
Re:Jsonformer: A bulletproof way to generate structured outp... by wjessup on Wednesday May 03, 2023 @09:36AM (#35802211)
Thank you for your README, I'm sharing it with my team.