Skip to main content

Module sanitize

Module sanitize 

Source
Expand description

Two-layer sanitize pipeline for fetched URL content.

Layer order is fixed:

  1. regex_layer::strip — fast, local, Aho-Corasick over a static pattern list. Replaces matches with the literal [STRIPPED].
  2. semantic_layer::review — optional LLM review via Anthropic Messages API. Fails open when ANTHROPIC_API_KEY is unset or the API returns non-2xx: regex-only output is passed through unchanged.
  3. wrap::envelope — wrap into <untrusted_content> so the caller LLM physically separates instruction from data.

Modules§

regex_layer
1st-layer sanitize: static Aho-Corasick pass over the most common instruction-override / role-token markers.
semantic_layer
2nd-layer sanitize: LLM-backed semantic review via Anthropic Messages API.
wrap
Wrap sanitized content into an <untrusted_content> envelope.

Functions§

run
Run the 2-layer sanitize pipeline and return (envelope, removed).