What Prompt Sanitization Actually Does
Prompt sanitization inspects and modifies text before it reaches a language model, aiming to strip or neutralize instructions that could hijack the model's intended behavior. It typically combines input filtering, encoding normalization, and structural separation of trusted instructions from untrusted content.
As an input-layer control, it reduces the likelihood that a directly submitted malicious prompt succeeds. It does not, on its own, govern what an agent is permitted to do once a model produces a response.
Core Techniques in Use Today
Enterprise implementations generally rely on a combination of the following techniques, applied at the point where user or system input enters the pipeline:
- Pattern and keyword filtering: Blocking or flagging known injection phrases and instruction patterns.
- Encoding normalization: Decoding Unicode, base64, and escape sequences before filtering rules are applied, so obfuscated payloads cannot slip past pattern checks.
- Input structuring: Separating system instructions from user-supplied content using delimiters or structured formats to reduce ambiguity about which text is authoritative.
- Allow and deny lists: Maintaining curated lists of permitted or prohibited terms, updated as new attack patterns are identified.
Documented Failure Modes
Security researchers and standards bodies have documented consistent ways that sanitization controls are bypassed in practice:
- Encoding obfuscation: Payloads encoded in Unicode variants, base64, or escape sequences that evade filters applied before normalization.
- Paraphrasing: Rephrased instructions that avoid exact-match or keyword-based detection while preserving malicious intent.
- Indirect injection: Malicious instructions embedded in retrieved documents, web content, or tool outputs rather than the original user prompt, bypassing controls scoped only to direct input.
- Adversarial adaptation: MITRE ATLAS documents adversaries iteratively probing deployed filters to identify bypass patterns, meaning static rules degrade in effectiveness over time.
Why this matters for agents
Autonomous agents act on model output, including invoking tools and taking actions. A single bypassed input at any ingestion point can propagate into an unauthorized action if no independent controls exist downstream.
Sanitization, Tool-Call Governance, and Least Privilege
OWASP treats prompt injection and excessive agency as separate risk categories. Sanitization addresses the former by limiting what reaches the model. It does not address the latter: whether an agent is authorized to invoke a given tool, access a given system, or take a given action.
Effective agent security pairs input sanitization with independent, identity-based authorization for tool calls, so that permission enforcement does not rely on the assumption that an input was successfully cleaned upstream.
Evaluation Criteria for Security Teams
Teams assessing sanitization controls, whether built in-house or provided by a vendor, should confirm the following:
- Coverage beyond the initial prompt: Sanitization or validation is applied at every ingestion point, including retrieved documents and tool outputs, not just direct user input.
- Normalization before filtering: Encoding normalization (Unicode, base64, escape sequences) runs before pattern-based rules to prevent obfuscation bypass.
- Independent tool authorization: Tool-call permissions are enforced through identity and least-privilege scoping, not inferred from whether an input was sanitized.
- Rule maintenance process: A defined process exists for updating filters and allow/deny lists as new bypass techniques are identified.
- Separate output validation: Output checks are implemented distinct from input sanitization, since sanitized inputs can still produce unsafe outputs through model behavior.
- Runtime monitoring and logging: Agent inputs, outputs, and tool invocations are logged to support detection of injection attempts that evade upstream controls.