Module constraints

Module constraints 

Source
Expand description

Constraint validation system for LLM-parsed values.

This module provides runtime validation similar to BAML’s @assert and @check annotations.

§Design

Constraints are validated during deserialization and can either:

  • Assert (@assert): Fail deserialization if the constraint fails
  • Check (@check): Track the result but don’t fail deserialization

§Example

use tryparse::constraints::{Constraint, ConstraintLevel, ConstraintResult};

// Define a constraint that age must be positive
let age_positive = Constraint::new(
    ConstraintLevel::Assert,
    "age_positive",
    "age must be greater than 0"
);

// In your deserializer, validate the constraint
let age: i64 = 25;
let result = age_positive.validate(age > 0);
assert!(result.passed());

Structs§

Constraint
A constraint that validates a condition.
ConstraintResult
Result of a constraint validation.
ConstraintResults
Collection of constraint validation results.

Enums§

ConstraintLevel
Level of constraint enforcement.