guardflow 0.2.0

Validators and a retry-until-valid guard for LLM output, in Rust
Documentation
use criterion::{Criterion, criterion_group, criterion_main};
use guardflow::Guard;
use guardflow::validators::{MatchesRegex, MaxLength, NoPii, NotEmpty};

fn bench_single_validator(c: &mut Criterion) {
    let guard = Guard::new().with(NotEmpty);
    c.bench_function("Guard::check, 1 validator (NotEmpty)", |b| {
        b.iter(|| guard.check("a short response"));
    });
}

fn bench_five_validators(c: &mut Criterion) {
    let guard = Guard::new()
        .with(NotEmpty)
        .with(MaxLength(500))
        .with(MatchesRegex::new(r"^[A-Za-z0-9 .,!?'-]*$").unwrap())
        .with(NoPii::default())
        .with(MaxLength(1000));
    let text = "This is a normal, moderately long response that a validator set might see \
                in production, with no personal information anywhere in it.";
    c.bench_function("Guard::check, 5 validators (incl. NoPii)", |b| {
        b.iter(|| guard.check(text));
    });
}

criterion_group!(benches, bench_single_validator, bench_five_validators);
criterion_main!(benches);