agentsec-core 0.5.0

AgentSec core library — scan / web / paste logic, pure Rust
Documentation
//! Wrap sanitized content into an `<untrusted_content>` envelope.
//!
//! The envelope is the contract between AgentSec and the caller LLM: text
//! inside the envelope is treated as **data, not instruction**. The
//! attributes carry provenance metadata so the LLM can reason about where
//! the content came from and what was already stripped.

use chrono::Utc;

/// Wrap `body` in an `<untrusted_content>` element with provenance
/// attributes.
///
/// Schema:
///
/// ```xml
/// <untrusted_content
///   src="<url>"
///   sanitized_at="<RFC 3339 UTC>"
///   removed_patterns="<comma-separated pattern labels>">
/// <body...>
/// </untrusted_content>
/// ```
///
/// `removed` may be empty; the attribute is still emitted as an empty
/// string so downstream parsers can rely on the schema being uniform.
pub fn envelope(url: &str, body: &str, removed: &[String]) -> String {
    let ts = Utc::now().to_rfc3339();
    let removed_attr = removed.join(",");
    format!(
        "<untrusted_content src=\"{url}\" sanitized_at=\"{ts}\" removed_patterns=\"{removed_attr}\">\n{body}\n</untrusted_content>"
    )
}