1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//! 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.
use crateLlmConfig;
use crateResult;
/// Run the 2-layer sanitize pipeline and return `(envelope, removed)`.
///
/// `envelope` is the wrapped `<untrusted_content>...</untrusted_content>`
/// string ready to hand to the caller LLM; `removed` is the cumulative
/// list of pattern labels stripped by both layers.
///
/// # Errors
///
/// Returns [`crate::Error::Http`] only if the semantic layer's HTTP call
/// fails before the fail-open fallback engages (e.g. TLS handshake
/// failure). API non-2xx is **not** an error here — see
/// [`semantic_layer::review`].
pub async