tryparse 0.1.0

Multi-strategy parser for messy real-world data. Handles broken JSON, markdown wrappers, and type mismatches.
Documentation
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 tryparse::parse;
use serde::Deserialize;

#[derive(Deserialize, Debug)]
struct User {
    name: String,
    age: u32,
}

// Parse messy LLM output with unquoted keys and string numbers
let messy_response = r#"{name: "Alice", age: "30"}"#;

let user: User = parse(messy_response).unwrap();
assert_eq!(user.name, "Alice");
assert_eq!(user.age, 30); // 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 tryparse::{parse_with_candidates, parser::FlexibleParser};
use serde::Deserialize;

#[derive(Deserialize)]
struct Data {
    value: i32,
}

let response = r#"{"value": "42"}"#;

// Get all candidates with metadata
let (result, candidates) = parse_with_candidates::<Data>(response).unwrap();

// Or use the parser directly
let parser = FlexibleParser::new();
let flex_values = parser.parse(response).unwrap();