AnyRepair
A Rust crate for repairing malformed LLM responses across multiple formats (JSON, YAML, Markdown, XML, TOML, CSV, INI, Diff).
Quick Start
Installation
[]
= "0.1.10"
Basic Usage
use repair;
// Auto-detect format and repair
let malformed = r#"{"name": "John", age: 30,}"#;
let repaired = repair?;
println!; // {"name": "John", "age": 30}
CLI
# Install
# Auto-detect and repair
# Format-specific repair
# Batch process multiple files
# Custom rules management
# Stream large files
# Plugin management
# Validation without repair
What's New
v0.1.10 - Latest Release
🔧 8 Format Support
- JSON, YAML, Markdown, XML, TOML, CSV, INI, Diff/Unified Diff
- Auto-detection from malformed content
- Format-specific validation and repair strategies
🐍 Python-Compatible API
- Drop-in compatible with Python's
jsonrepairlibrary jsonrepair()function andJsonRepairclass API- Easy migration from Python to Rust projects
🔌 MCP Server Integration
- Native Claude Desktop integration via MCP
- 10 MCP tools for format-specific and auto-detect repair
- Simple configuration, zero-dependency setup
📦 Enterprise Features
- Analytics: Track repair metrics, success rates, performance
- Batch Processing: Multi-file processing with format auto-detection
- Validation Rules: Custom rule engine for format validation
- Audit Logging: Compliance logging with event tracking
- Confidence Scoring: Assess repair quality (0.0-1.0 scale)
⚡ Performance & Quality
- 326+ test cases with 100% pass rate
- 99.6% improvement from regex caching
- Streaming support for files larger than RAM
- Parallel strategy application using rayon
- 94% binary size reduction (1.5 MB release builds)
🎯 Plugin System
- Extensible plugin architecture for custom repair strategies
- WASM-based sandboxing support
- Plugin configuration via TOML
- Hot-reload capabilities
See CHANGELOG.md for complete version history.
Why AnyRepair?
LLMs often generate malformed structured data. AnyRepair fixes common issues:
- JSON: Missing quotes, trailing commas, syntax errors
- YAML: Indentation issues, missing colons
- Markdown: Malformed headers, broken links
- XML/TOML/CSV/INI/Diff: Format-specific repairs
Key Features:
- ✅ Auto-detects format from damaged content
- ✅ Multi-format support (8 formats)
- ✅ High performance (regex caching, optimized binaries)
- ✅ MCP server for Claude integration
- ✅ Streaming support for large files
- ✅ 326+ tests, 100% pass rate
Usage Examples
Multi-Format Auto-Detection
use repair;
// JSON - auto-detected and repaired
let json = repair?;
// Output: {"key": "value"}
// YAML - auto-detected and repaired
let yaml = repair?;
// Markdown - auto-detected and repaired
let markdown = repair?;
// Diff - auto-detected and repaired
let diff = repair?;
Python-Compatible JSON API
use ;
// Function-based API (like Python's jsonrepair)
let repaired = jsonrepair?;
// Class-based API (like Python's JsonRepair class)
let mut jr = new;
let repaired1 = jr.jsonrepair?;
let repaired2 = jr.jsonrepair?;
Format-Specific Repairers
use ;
// JSON
let mut json_repairer = new;
let repaired = json_repairer.repair?;
// YAML
let mut yaml_repairer = new;
let repaired = yaml_repairer.repair?;
// Diff
let mut diff_repairer = new;
let repaired = diff_repairer.repair?;
// Check if repair is needed
if json_repairer.needs_repair
Streaming Large Files
use StreamingRepair;
use File;
use BufReader;
let input = new;
let mut output = create?;
// Configure buffer size (default 8192 bytes)
let processor = with_buffer_size;
// Process with automatic format detection
processor.process?;
// Or specify format explicitly
processor.process?;
Batch Processing
use BatchProcessor;
let processor = new;
// Process directory with options
let results = processor.process_directory?;
// Get per-file results
for result in results
// Get analytics
let analytics = processor.get_analytics;
println!;
MCP Server Integration
The MCP server provides seamless integration with Claude Desktop:
# Install and run MCP server
Configure in claude_desktop_config.json:
Available MCP Tools:
repair- Auto-detect and repair any formatrepair_json,repair_yaml,repair_markdown,repair_xmlrepair_toml,repair_csv,repair_ini,repair_diffvalidate- Validate content without repair
Usage in Claude:
Please repair this JSON: {"name": "John", age: 30,}
(Claude will use the anyrepair MCP tool to fix it)
See MCP_SERVER.md for complete documentation.
Supported Formats
| Format | Common Issues Fixed |
|---|---|
| JSON | Missing quotes, trailing commas, malformed numbers, boolean/null values |
| YAML | Indentation, missing colons, list formatting, document separators |
| Markdown | Headers, code blocks, lists, tables, links, images |
| XML | Unclosed tags, malformed attributes, missing quotes, entity encoding |
| TOML | Missing quotes, malformed arrays, table headers, dates |
| CSV | Unquoted strings, malformed quotes, extra/missing commas |
| INI | Malformed sections, missing equals signs, unquoted values |
| Diff | Missing hunk headers, incorrect line prefixes, malformed ranges |
Advanced Features
Custom Rules
# Add custom repair rule via CLI
# List all rules
# Enable/disable rules
# Remove a rule
Configuration file (anyrepair.toml):
# Custom rules configuration
[[]]
= "fix_trailing_comma"
= "json"
= ",\\s*}"
= "}"
= 95
[[]]
= "fix_js_comments"
= "json"
= "//.*\\n"
= ""
= 80
Plugin System
Extend functionality with custom repair strategies:
use ;
;
Plugin configuration (plugins.toml):
[[]]
= "custom_json_rules"
= "./plugins/custom_json_rules.so"
= true
= 85
= ["json"]
[]
= true
= false
See Plugin Development Guide for complete documentation.
Enterprise Features
Analytics:
use AnalyticsTracker;
let tracker = new;
tracker.track_repair_result;
let metrics = tracker.get_metrics;
println!;
Validation Rules:
use ValidationRulesEngine;
let engine = new;
let violations = engine.validate?;
for violation in violations
Audit Logging:
use AuditLogger;
let logger = new;
logger.log_repair?;
logger.log_validation?;
Confidence Scoring:
use ConfidenceScorer;
let scorer = new;
let confidence = scorer.score;
if confidence < 0.8
See Enterprise Features for details.
Performance
- Regex Caching: 99.6% performance improvement over uncached operations
- Optimized Binaries: 1.5 MB release builds (94% size reduction)
- Parallel Processing: Multi-threaded strategy application with rayon
- Streaming: Process files larger than available RAM using configurable buffers
- Lazy Evaluation: Skip unnecessary strategies for faster repairs
Build Profiles:
# Standard release (size-optimized)
# Distribution profile (maximum optimization)
Testing
- 326+ test cases with 100% pass rate
- 204 library tests
- 26 streaming tests
- 36 fuzz tests
- 18 complex damage tests
- 18 complex streaming tests
- 4 integration tests
- 2 doctests
- Fuzz testing using proptest for robustness
- Snapshot testing with insta for regression prevention
- Integration tests for end-to-end workflows
- MCP test coverage with 43 comprehensive tests
See TEST_SUMMARY.md for details.
Comparison
| Feature | AnyRepair | json-repair-rs | json5 | Python jsonrepair |
|---|---|---|---|---|
| Multi-format | ✅ 8 formats | ❌ JSON only | ❌ JSON only | ❌ JSON only |
| Auto-detection | ✅ Smart detection | ❌ | ❌ | ❌ |
| MCP integration | ✅ Native | ❌ | ❌ | ❌ |
| Streaming | ✅ Large file support | ❌ | ❌ | ❌ |
| Custom rules | ✅ CLI + API | ❌ | ❌ | ❌ |
| Plugin system | ✅ WASM plugins | ❌ | ❌ | ❌ |
| Python API | ✅ Compatible | ❌ | ❌ | ✅ Native |
| Enterprise features | ✅ Analytics, audit | ❌ | ❌ | ❌ |
| Language | Rust | Rust | Rust | Python |
| Binary size | 1.5 MB | ~500 KB | ~200 KB | N/A |
Why AnyRepair?
- Most comprehensive format support (8 formats vs JSON-only alternatives)
- Only Rust crate with Python-compatible API and MCP integration
- Enterprise-grade features: analytics, audit logging, validation rules
- Battle-tested with 326+ tests covering real-world LLM failures
Documentation
- ARCHITECTURE.md - System design and architecture
- MCP_SERVER.md - MCP server integration guide
- PLUGIN_DEVELOPMENT.md - Plugin development guide
- TEST_SUMMARY.md - Test coverage details
- CHANGELOG.md - Version history and changes
- INDEX.md - Complete documentation index
- STREAMING_FEATURE.md - Streaming support details
- BUILD_OPTIMIZATION.md - Build optimization guide
Quick Links
- Report Issues: GitHub Issues
- Contributing: See CONTRIBUTING.md (if available)
- Changelog: CHANGELOG.md
- API Docs: docs.rs
Examples
See the examples/ directory for:
- example_plugin.rs - Custom plugin implementation
- mcp_repair_json.rs - MCP JSON repair usage
- mcp_multi_format.rs - Multi-format MCP repair
- mcp_server_usage.rs - MCP server setup and usage
Run examples:
Roadmap
See TODO.md for planned features and improvement areas. Highlights include:
- Additional format support (Properties, .env, GraphQL, SQL, Protobuf)
- CLI enhancements (watch mode, interactive mode, diff preview)
- Web interface and REST API
- Language bindings (Python, Node.js, Go)
- LSP integration and VS Code extension
- Advanced features (format-preserving repairs, LLM-assisted repairs)
License
Apache-2.0