fn sanitize_for_context(content: &str) -> StringExpand description
Sanitizes memory content before injection into context (CRIT-004).
This function strips potential prompt injection patterns from memory content to prevent stored memories from manipulating the LLM’s behavior.
§Security Measures
- Strips system message impersonation patterns (
<system>,[SYSTEM], etc.) - Removes role switching attempts (
<user>,<assistant>, etc.) - Filters instruction override phrases (“ignore previous instructions”, etc.)
- Removes zero-width and invisible Unicode characters
- Enforces maximum content length to prevent context flooding
- Logs when content is sanitized for security auditing
§Arguments
content- The raw memory content to sanitize.
§Returns
Sanitized content safe for injection into LLM context.