tryparse-0.1.0 has been yanked.
tryparse
A forgiving parser that converts messy LLM responses into strongly-typed Rust structs.
Schema-Aware Parsing
The library now supports compile-time schema information to guide parsing decisions.
Use the SchemaInfo trait (typically via derive macro) to provide type information.
This library handles common issues in LLM outputs like:
- JSON wrapped in markdown code blocks
- Trailing commas
- Single quotes instead of double quotes
- Unquoted object keys
- Type mismatches (string numbers, etc.)
Quick Start
use parse;
use Deserialize;
// Parse messy LLM output with unquoted keys and string numbers
let messy_response = r#"{name: "Alice", age: "30"}"#;
let user: User = parse.unwrap;
assert_eq!;
assert_eq!; // Automatically coerced from string
Features
- Multi-Strategy Parsing: Tries multiple approaches to extract JSON
- Smart Type Coercion: Converts between compatible types automatically
- Transformation Tracking: Records all modifications made during parsing
- Candidate Scoring: Ranks multiple interpretations by quality
- Zero Configuration: Works out of the box with sensible defaults
Advanced Usage
For more control over the parsing process:
use ;
use Deserialize;
let response = r#"{"value": "42"}"#;
// Get all candidates with metadata
let = .unwrap;
// Or use the parser directly
let parser = new;
let flex_values = parser.parse.unwrap;