Skip to main content

Module parser

Module parser 

Source
Expand description

JSON-ish parser for handling malformed LLM outputs.

Implements a three-phase parsing strategy:

  1. Strip & Fix: Remove markdown, fix trailing commas, normalize quotes
  2. Standard Parse: Try serde_json (fast path)
  3. Lenient Parse: Character-by-character state machine for incomplete/malformed JSON

§Example

use simple_agents_healing::parser::JsonishParser;

let parser = JsonishParser::new();

// Parse markdown-wrapped JSON
let malformed = r#"```json
{"key": "value", "num": 42,}
```"#;

let result = parser.parse(malformed).unwrap();
assert_eq!(result.value["key"], "value");
assert_eq!(result.value["num"], 42);

Structs§

JsonishParser
Three-phase JSON parser for malformed LLM outputs.
ParserConfig
Parser configuration options.

Type Aliases§

ParserResult
Result of parsing with coercion tracking.