Expand description
Tolerant JSON parsing for LLM outputs.
LLMs frequently produce malformed JSON: trailing commas, unescaped quotes,
incomplete brackets, or markdown-wrapped code blocks. Historically this
logic lived in lc-core, but ToolCall::parse_arguments (in this crate)
parses the same kind of LLM-generated JSON and cannot depend on lc-core.
So the repair pipeline lives here so that every parser of LLM JSON — in
lc-shared and lc-core alike — converges on a single tolerant parser.
Enums§
- Json
Repair Error - Error types for tolerant JSON parsing.
Functions§
- extract_
bracket_ pair - Finds the outermost
[...]or{...}bracket pair. - fix_
unescaped_ quotes - Escapes
"characters that appear inside string values but are not the string’s closing quote. - parse_
tolerant_ json - Parses LLM JSON output with automatic repair of common errors.
- remove_
trailing_ commas - Removes trailing commas before closing brackets.
- repair_
json - Repairs common LLM JSON mistakes and extracts the JSON portion.
- strip_
code_ fences - Strips markdown code fences from the text.
- truncate_
to_ matching_ bracket - Truncates to the last matching closing bracket if there’s trailing garbage.