Skip to main content

Crate llm_prefix_match

Crate llm_prefix_match 

Source
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§

PrefixMatcher
Checks whether LLM outputs start with any of a set of expected prefixes.

Enums§

MatchMode
Match mode.
MatchResult
Result of a prefix match check.