Skip to main content
Prompt injection attacks occur when malicious instructions embedded in external content (web pages, user inputs, tool responses) attempt to override or hijack your agent’s behavior. Declaw’s injection defense scans your agent’s outbound requests before they reach LLM APIs — if an injected instruction from a tool or web response is carried into an outbound request, the classifier catches it there. (Inbound responses are passed through to the agent unchanged; they aren’t blocked or rewritten on the way in.) Deeper session-aware indirect-injection detection — catching a benign-looking action driven by earlier poisoned context — is handled by the optional LLM judge (InjectionJudgeConfig), which is off by default.

Enable injection defense

The shorthand injection_defense=True enables it with the defaults (action="log_only", threshold=0.95):

InjectionDefenseConfig model

Domain scoping

Injection defense is opt-in per domain. Unlike PII or toxicity scanning — where an empty domain list means all egress is scanned — injection scanning runs only on the destination hosts you list in domains. If domains is empty or unset, no injection scanning happens at all. Set domains to the endpoints whose request and response bodies you actually want inspected — typically your agent’s model/LLM endpoint(s):
Each entry in domains can be:
Scoping injection to your model endpoint keeps scanning focused where prompts and tool results actually flow, and avoids inspecting unrelated traffic (package registries, object storage, telemetry). Remember the opt-in rule: if you enable injection defense but leave domains empty, nothing is scanned.

InjectionAction enum

How detection works

Without the Guardrails Service, the proxy uses a pattern library to detect known injection attempts:
With the Guardrails Service deployed, an ML classifier scores each outbound request body (0.0–1.0), with a second-tier LLM judge backstopping it on ambiguous cases. When the score exceeds threshold, the configured action is applied.

How injection is caught

Enforcement happens at the agent’s outbound boundary — Declaw gates what the agent sends, it does not block or rewrite inbound responses: Direct injection — the agent’s own outbound request body is scanned; if it scores over threshold, the configured action is applied. Indirect injection — untrusted inbound content (web pages, API responses, tool outputs) is passed through to the agent unchanged, not blocked on the way in. If that content is carried verbatim into an outbound request, the classifier catches it. Catching a benign-looking action redirected by earlier poisoned context requires the optional LLM judge (InjectionJudgeConfig, off by default).

Sensitivity thresholds

Example: agent protected from indirect injection

Combining with transformation rules

Use TransformationRule for deterministic pattern removal alongside probabilistic injection defense:
For production deployments handling sensitive agent workloads, deploy the Guardrails Service to use the ML classifier plus an LLM judge. The built-in pattern library covers known attack signatures but cannot detect novel injection techniques that the model can.