Expand description
Extraction of JSON payloads from raw LLM output
LLMs rarely return a bare JSON document: the payload is typically
wrapped in a Markdown code fence, surrounded by explanatory prose,
or both. This module locates the JSON payload(s) inside such output
so they can be fed to sanitize_json and the
repair functions.
§Pipeline position
Extraction is stage 0 of the repair pipeline:
raw LLM output --extract_json--> JSON-ish text --sanitize_json--> valid JSON
--repair_*-------> typo-fixed JSON§Design
Extraction is intentionally lenient: the returned slice does not have to be valid JSON (it may contain trailing commas or be truncated) — that is what the sanitize stage is for. Balanced-delimiter tracking is string-aware, so braces inside string literals do not confuse it.
Functions§
- extract_
json - Extract the first JSON payload from raw LLM output.
- extract_
json_ blocks - Extract all top-level JSON payloads from raw LLM output.
- strip_
code_ fences - Strip a Markdown code fence wrapper from the input.