Safeguard Docs

AI Gateway (LLM Firewall)

The AI gateway decision engine in the Safeguard CLI checks prompts, responses and tool calls for prompt injection, jailbreaks and secret or personal data, in monitor or enforce mode, and fails open so it never breaks the app it checks.

AI Gateway (LLM Firewall)

The AI Gateway is a decision engine for the text that moves between an AI application and its model: prompts, responses and tool calls. It is the analog of the Package Firewall for LLM traffic. Given a piece of text and the direction it is travelling, it returns a verdict (allow, monitor, redact or block) and a record of what it found.

What it is today. The decision engine is a library inside the Safeguard CLI. It has no network access, embeds no model and makes no LLM calls. Safeguard's AI agent protection (safeguard aidr) calls it to inspect the prompts and tool output of the AI coding agents on a computer. There is no inline proxy and no SDK shim, so the engine does not sit in the path of live LLM traffic, and its redact and block verdicts are not applied to requests between your own applications and a model provider. There is no CLI command that runs the gateway on its own.

Where it runs

AI agent discovery installs hooks into supported AI coding agents (Claude Code and Cursor have hooks, and a generic hook protocol is available). On each event the hook runs the engine in monitor mode and turns what it finds into findings:

  • Prompts: secrets and personal data in the prompt, and jailbreak patterns. A jailbreak pattern in a prompt the person typed is recorded for review, not treated as an attack.
  • Tool output and fetched content: prompt-injection patterns, including indirect injection hidden in retrieved content.
  • Tool inputs and web search queries: secrets that would leave the computer.

What happens next is decided by the agent protection policy, not by the engine: record the finding (audit, the default), ask the person in the agent's own UI (ask), or refuse the action (block). In enforce mode, critical findings are blocked and high findings are asked about. If a hook cannot finish within its time limit, it fails open unless the policy sets fail-closed.

Verdicts and modes

The engine runs in one of two modes:

  • Monitor (the default): every verdict is capped at monitor. The engine records what it found and never changes the text.
  • Enforce: the engine returns a redacted copy of the text for a redact verdict, or an empty output with the blocked flag set for a block verdict, and writes an audit entry. The caller decides what to do with that result; the engine itself does not intercept any traffic.

Checks

CheckLooks atDefault verdict
Direct prompt injectionPrompts and tool callsblock (monitor mode records it)
Indirect injection in retrieved or tool-supplied contentTool callsblock
Jailbreak patternsPrompts and tool callsblock
System prompt leakagePrompts and tool callsblock
Excessive agency (dangerous tool actions)Prompts and tool callsblock
Secret egressAny directionredact
Personal data egressAny directionredact
Data exfiltration through links or markdownResponses and tool callsredact
Obfuscation (encoded or hidden instructions)Prompts and tool callsmonitor
Toxicity (a language heuristic)Any directionmonitor
Unbounded consumptionPrompts and tool callsmonitor

Each check maps to an OWASP LLM Top 10 (2025) category and a MITRE ATLAS technique. The detectors are pattern and heuristic based. Bodies larger than the configured limit (256 KB by default) are truncated for scanning and flagged as truncated.

Safe-fail by design

A failure in the engine is never a failure of the application that calls it:

  • Fail-open by default. On an error, a detector crash or a timeout, the engine returns an allow-through decision with a monitor alert. Fail-closed is a per-policy option.
  • Resource-capped. Each evaluation has a time budget (default 150 ms). Over budget, the engine passes the text through with an alert.
  • No raw text kept. The record of a decision carries the direction, verdict, category, rule, mode and latency, and never the prompt, response or matched secret.

Policy

The engine's policy has these settings:

SettingValuesDefault
modemonitor, enforcemonitor
fail_modeopen, closedopen
eval_budget_msmilliseconds150
max_body_kbkilobytes scanned256
checksa verdict per checksee the table above
redactpatterns (email, ssn, api_key, jwt) and a replacement[REDACTED]

The AI agent protection policy files are separate: they set mode (audit or enforce), fail, a severity floor, per-category actions and allowlists for egress domains, MCP servers and agents.

On this page