Outputguard: A Python Library for Automatic JSON Repair in LLM Outputs
Install outputguard via pip and use its JSON Schema validation and repair strategies to fix malformed LLM outputs.
Add outputguard to your LLM pipeline to automatically repair JSON outputs.
Summary
A new Python library called outputguard has been released to validate and automatically repair malformed LLM outputs against JSON Schema. The library implements 15 repair strategies, applied in a specific priority order that first fixes encoding issues before structural problems. It supports JSON, YAML, TOML, and Python literals, and re‑parses the output after each strategy to ensure earlier fixes are not undone. Outputguard is MIT‑licensed, contains 2,001 tests, and has no dependencies on LLM providers, making it easy to integrate into any pipeline.
Installation is as simple as pip install outputguard, after which developers can use the library to enforce schema compliance and recover from common failures such as markdown fences, trailing commas, and truncated objects. The author built the tool after observing that many models produce structurally valid JSON but still violate schemas or truncate responses. The library’s design prioritises encoding fixes, then structure, and includes a comprehensive set of repair strategies to handle a wide range of failure modes. A blog post detailing the findings and usage instructions is available on thecrosswalk.news.
Key changes
- Python library outputguard validates against JSON Schema
- 15 repair strategies ordered by priority
- Handles JSON, YAML, TOML, and Python literals
- Re‑parses after each strategy to preserve earlier fixes
- MIT‑licensed with 2,001 tests and no LLM provider dependencies
- Installation via pip install outputguard
- Fixes common failures: markdown fences, trailing commas, truncated objects
- Blog post with detailed findings available on thecrosswalk.news