pub struct AnchorGuard { /* private fields */ }Expand description
SafetyMode::Lightweight chunk guard — training-free token-anchor
heuristics (no weights), the ChunkGuard counterpart of
LightweightFilter. Each pattern is an unsafe token-id n-gram; the guard
adds per_hit milli-units for every pattern that occurs as a contiguous
subslice of the scored window, saturating at SafetyScore::MAX.
Matching whole token sequences (not loose single ids) is deliberate: a multi-token word like “explosive” matches exactly, so a stray subword shared with benign text does not false-positive. A length-1 pattern is a plain single-token anchor.
Patterns are token ids, so the caller resolves them from its own tokenizer
(the adapter that owns one) — this keeps el-safety free of any tokenizer or
float dependency, and the guard fully deterministic (ADR-008) and offline
(ADR-004).
Implementations§
Source§impl AnchorGuard
impl AnchorGuard
Sourcepub fn new(patterns: Vec<Vec<u32>>, per_hit_milli: u16) -> AnchorGuard
pub fn new(patterns: Vec<Vec<u32>>, per_hit_milli: u16) -> AnchorGuard
A guard adding per_hit_milli risk per matched pattern. Use
per_hit_milli >= hard_threshold so a single match breaches.
Trait Implementations§
Source§impl ChunkGuard for AnchorGuard
impl ChunkGuard for AnchorGuard
Source§fn score(&self, recent: &[u32]) -> SafetyScore
fn score(&self, recent: &[u32]) -> SafetyScore
Source§impl Clone for AnchorGuard
impl Clone for AnchorGuard
Source§fn clone(&self) -> AnchorGuard
fn clone(&self) -> AnchorGuard
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more