i wrote an extremely lenient parser in
i wrote an extremely lenient parser in typescript (published to npm) specifically to handle bad JSON output from LLMs: https://github.com/acusti/uikit/tree/main/packages/parsing
i adapted it originally from langchain (https://github.com/langchain-ai/langchainjs/blob/215dd52/langchain-core/src/output_parsers/json.ts#L58) but added a ton of extra parsing to deal with real-world garbage serialized json i’ve received from LLMs over the last year (see examples in the unit tests).
2 Replies
This is awesome! So if I'm understanding it right, it'll actually also strip text-based responses if it sees JSON hidden within them, correct?
I've needed something like this for a while, been manually trying to parse out JSON from responses so this is very useful 😄
in case llama 2 decides to give you a markdown table to represent the JSON😂
that’s right, it’ll strip any pre-amble or post-amble text and return any JSON it finds inside. though if there are multiple discrete chunks of JSON inside, it would only return one of those chunks. and yeah, the time llama 2 gave me a markdown table with the keys in the first column and the values in the second was… quite something.