Expand description
llm-prefix-match: gate LLM outputs based on expected prefix patterns.
When you need a model to start its response a certain way (e.g. JSON, a keyword, or a specific token), this crate lets you check, assert, or strip that prefix before passing the response downstream.
use llm_prefix_match::{PrefixMatcher, MatchResult};
let m = PrefixMatcher::new().require_any(&["YES", "NO"]);
assert_eq!(m.check("YES, I agree"), MatchResult::Matched("YES".into()));
assert_eq!(m.check("Maybe"), MatchResult::NoMatch);Structs§
- Prefix
Matcher - Checks whether LLM outputs start with any of a set of expected prefixes.
Enums§
- Match
Mode - Match mode.
- Match
Result - Result of a prefix match check.