Skip to main content

Crate yaml_repair

Crate yaml_repair 

Source
Expand description

§yaml-repair

Repair messy YAML emitted by LLMs into something a real YAML parser will accept.

Fixes applied:

  1. Strip yaml / fences and surrounding prose.
  2. Normalize CRLF and CR line endings to LF.
  3. Convert leading tabs to 2 spaces (YAML forbids leading tabs in indentation).
  4. Dedent so the shallowest non-empty line is at column 0.
  5. Trim trailing whitespace on each line.

§Example

use yaml_repair::repair;
let raw = "Sure:\n```yaml\n  name: Claude\n  tools:\n    - read\n    - write\n```";
let fixed = repair(raw);
assert!(fixed.starts_with("name: Claude"));
assert!(!fixed.contains("```"));

Functions§

repair
Clean raw and return YAML-parser-ready text.