pub struct ContentSanitizer { /* private fields */ }Expand description
Stateless pipeline that sanitizes untrusted content before it enters the LLM context.
Constructed once at Agent startup from ContentIsolationConfig and held as a
field on the agent. All calls to sanitize() are synchronous.
classify_injection() is a separate async method for ML-backed detection (feature classifiers).
Implementations§
Source§impl ContentSanitizer
impl ContentSanitizer
Sourcepub fn new(config: &ContentIsolationConfig) -> ContentSanitizer
pub fn new(config: &ContentIsolationConfig) -> ContentSanitizer
Build a sanitizer from the given configuration.
Sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Returns true when the sanitizer is active (i.e. enabled = true in config).
Sourcepub fn sanitize(&self, content: &str, source: ContentSource) -> SanitizedContent
pub fn sanitize(&self, content: &str, source: ContentSource) -> SanitizedContent
Run the four-step sanitization pipeline on content.
Steps:
- Truncate to
max_content_sizebytes on a UTF-8 char boundary. - Strip null bytes and non-printable ASCII control characters.
- Detect injection patterns (flag only, do not remove).
- Wrap in spotlighting delimiters (unless
Trustedor spotlight disabled).
When enabled = false, this is a no-op: content is returned as-is wrapped in
a SanitizedContent with no flags.
Replace delimiter tag names that would allow content to escape the spotlighting
wrapper (CRIT-03). Uses case-insensitive regex replacement so mixed-case variants
like <Tool-Output> or <EXTERNAL-DATA> are also neutralized (FIX-03).
pub fn apply_spotlight( content: &str, source: &ContentSource, flags: &[InjectionFlag], ) -> String
Trait Implementations§
Source§impl Clone for ContentSanitizer
impl Clone for ContentSanitizer
Source§fn clone(&self) -> ContentSanitizer
fn clone(&self) -> ContentSanitizer
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for ContentSanitizer
impl RefUnwindSafe for ContentSanitizer
impl Send for ContentSanitizer
impl Sync for ContentSanitizer
impl Unpin for ContentSanitizer
impl UnsafeUnpin for ContentSanitizer
impl UnwindSafe for ContentSanitizer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request