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§
Structs§
- Output
Validation Error - Raised-error equivalent (returned from
check_or_raise). - Output
Validator - Runs a list of
Rules against an output string. All rules always run. - Rule
- A named rule check.
- Rule
Result - The outcome of running one rule against a string.
- Validation
Result - Aggregate result from checking all rules.