anyrepair-0.1.0 has been yanked.
AnyRepair
A Rust crate for repairing LLM responses including JSON, YAML, Markdown, and XML.
Features
- JSON Repair: Fixes common JSON issues including:
- Missing quotes and unescaped quotes
- Trailing commas and missing commas
- Missing braces and brackets
- Single quote to double quote conversion
- Unicode and special character handling
- Complex nested structures
- API response patterns and configuration files
- YAML Repair: Repairs YAML formatting issues including:
- Indentation problems
- Missing colons and list formatting
- Document separators
- Complex nested structures
- Markdown Repair: Fixes Markdown syntax issues including:
- Header spacing and formatting
- Code block fences and indentation
- List formatting and nesting
- Link and image syntax
- Bold and italic formatting
- Table formatting
- XML Repair: Repairs XML formatting issues including:
- Unclosed tags and malformed attributes
- Missing quotes around attribute values
- Invalid characters and self-closing tags
- XML declaration
- Auto-detection: Automatically detects the format and applies appropriate repairs
- Confidence scoring: Provides confidence scores for repair quality assessment
- CLI interface: Command-line tool for easy usage
- Comprehensive testing: 60+ test cases with snapshot testing covering real-world scenarios
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
Usage
Library Usage
use ;
// Auto-detect format and repair
let content = r#"{"name": "John", "age": 30,}"#;
let repaired = repair?;
println!; // {"name": "John", "age": 30}
// Specific format repair
let json_repairer = new;
let repaired_json = json_repairer.repair?;
// Check if repair is needed
if json_repairer.needs_repair
// Get confidence score
let confidence = json_repairer.confidence;
println!;
Advanced Examples
Complex JSON Repair
use JsonRepairer;
let damaged_json = r#"{
'name': "John",
"age": 30,
"hobbies": ["reading", "coding", "gaming",],
"address": {
"street": "123 Main St",
"city": "New York"
},
"isActive": true,
"score": 95.5,
}"#;
let repairer = new;
let repaired = repairer.repair?;
// Result: Valid JSON with all issues fixed
YAML Repair
use YamlRepairer;
let damaged_yaml = r#"name: John
age: 30
hobbies:
- reading
- coding
- gaming
address:
street: 123 Main St
city: New York"#;
let repairer = new;
let repaired = repairer.repair?;
Markdown Repair
use MarkdownRepairer;
let damaged_markdown = r#"#Header
Some **bold** text
- item1
- item2
1.item3"#;
let repairer = new;
let repaired = repairer.repair?;
// Result: Properly formatted Markdown
CLI Usage
# Auto-detect and repair
|
# Repair specific format
|
|
# Validate content
|
# Show confidence score
|
Architecture
graph TB
A[Input Content] --> B[Format Detection]
B --> C{Format Type}
C -->|JSON| D[JSON Repairer]
C -->|YAML| E[YAML Repairer]
C -->|Markdown| F[Markdown Repairer]
D --> G[Repair Strategies]
E --> G
F --> G
G --> H[Validation]
H --> I[Repaired Content]
subgraph "Repair Strategies"
J[Add Missing Quotes]
K[Fix Trailing Commas]
L[Fix Indentation]
M[Fix Headers]
N[Fix Code Blocks]
end
G --> J
G --> K
G --> L
G --> M
G --> N
API Reference
Core Traits
Repair: Main trait for content repair functionalityRepairStrategy: Trait for specific repair strategiesValidator: Trait for content validation
Repairers
JsonRepairer: Repairs JSON contentYamlRepairer: Repairs YAML contentMarkdownRepairer: Repairs Markdown content
Error Handling
The crate uses a custom RepairError enum for error handling:
Testing
The crate includes comprehensive tests with snapshot testing using insta:
# Run all tests
# Run tests with snapshot updates
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Run
cargo testto ensure all tests pass - Submit a pull request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Changelog
0.1.0
- Initial release
- JSON repair functionality with 5 core strategies
- YAML repair functionality with 4 core strategies
- Markdown repair functionality with 4 core strategies
- CLI interface with clap
- Comprehensive test coverage (60+ test cases)
- Auto-format detection
- Confidence scoring system
- Snapshot testing with insta
- Support for complex nested structures
- Unicode and special character handling
- Real-world damage scenario testing
- API response pattern repair
- Configuration file repair
- Performance benchmarking