Show HN: LLMs can generate valid JSON 100% of the time
I can make GPT4 return valid JSON simply by providing examples in the system message. This works nine times out of ten.<p>But it's still probabilistic, and nine times out of ten isn't good enough.<p>Occasionally it will hallucinate responses like this:<p>{"key1": "value1", "key2": "value2" for i in range(n)}<p>Re-prompting with the parsing error message is usually enough to get it on the second try.<p>But escaping double-quotes and newline characters is less reliable. Even after giving it multiple examples, it correctly escapes only about half the time.<p>Re-prompting for escaping errors still yields a ~50% success rate.