Skip to main content

Crate llm_output_validator

Crate llm_output_validator 

Source
Expand description

llm-output-validator: rule-based validator for LLM output strings.

Run AFTER the LLM produces a string. Enforce length, regex, allowed values, JSON parseability, no-PII, or custom predicates. All rules run (no short- circuit) so you get a complete picture of every failure in one pass.

use llm_output_validator::{OutputValidator, rules};

let v = OutputValidator::new(vec![
    rules::length(Some(10), Some(500)),
    rules::json_parseable(),
]);

let result = v.check("{\"key\": \"value\"}");
assert!(result.ok);
assert!(result.failed_rules.is_empty());

let bad = v.check("hi");
assert!(!bad.ok);
assert!(bad.failed_rules.contains(&"length".to_owned()));

Modules§

rules

Structs§

OutputValidationError
Raised-error equivalent (returned from check_or_raise).
OutputValidator
Runs a list of Rules against an output string. All rules always run.
Rule
A named rule check.
RuleResult
The outcome of running one rule against a string.
ValidationResult
Aggregate result from checking all rules.