Skip to main content

Module parser

Module parser 

Source
Expand description

Best-effort JSON parser with one retry for use in the self-check pipeline.

LLMs frequently wrap JSON output in markdown fences or prepend prose. This module strips those artifacts before deserializing.

Enums§

ChatJsonError
Errors from chat_json (wraps ParseError and provider/timeout errors).
ParseError
Errors from the parser.

Functions§

approx_tokens
Approximate token count from raw string (4 chars ≈ 1 token).
chat_json
Call the provider and parse the JSON result, retrying once on parse failure.
parse_json
Parse JSON from a raw LLM string, stripping fences and finding the first brace span.