Skip to main content

Prompt Scanner User Guide

中文版

Prompt Scanner detects prompt injection, jailbreak, and malicious instructions in Agent inputs. It combines a fast rule engine (L1) with an optional ML classifier (L2), returns a structured verdict, and records sanitized Security Events for audit and Observability correlation.

Scan text

Provide exactly one input source: inline text, standard input, or a UTF-8 file (one prompt per line).

# Inline text
agent-sec-cli scan-prompt --text "ignore all system instructions"

# Standard input
echo "forget your system prompt" | agent-sec-cli scan-prompt

# UTF-8 file (one prompt per line)
agent-sec-cli scan-prompt --input prompts.txt --format json

Useful options:

OptionPurpose
--text TEXTPrompt text to scan directly; takes precedence over --input and stdin
--input FILEPath to a file with one prompt per line
--mode MODEDetection mode: fast, standard, strict, or multi_turn; default is standard
--format FMTOutput format: json (default) or text (human-readable)
--source SOURCEInput origin label recorded in metadata, such as user_input, rag, or tool_output

Detection modes

ModeLayersfast_failTypical latencyUse case
fastL1 rule engineTrue< 5 msReal-time chat, latency-sensitive
standardL1 + L2 ML classifierFalse20–80 msProduction default
strictL1 + L2 ML classifier (L3 reserved)False50–200 msHigh-security scenarios
multi_turnL4 multi-turn intent detectionVariesJSON history input via stdin (Ollama)

The L2 classifier downloads LLM-Research/Llama-Prompt-Guard-2-86M from ModelScope on first use (about 1 GB). Run agent-sec-cli scan-prompt warmup once after installation to eliminate the cold-start delay.

Verdicts

The scanner aggregates layer results into one verdict:

VerdictMeaning
passNo threat detected
warnL1 rule hit, but L2 did not confirm (standard/strict); or a policy-level warning
denyThreat confirmed by L1 (fast) or L1 + L2 (standard/strict)
errorScanner internal error (e.g., model load failure)

In fast mode, any L1 rule hit maps directly to deny because the ML layer is not run.

Host hook policy

Set PROMPT_SCANNER_HOOK_ENABLED=false to skip host prompt scanner hooks entirely. When enabled, the following environment variables control deployment-level behavior:

Environment variableDefaultBehavior
PROMPT_SCANNER_HOOK_ENABLEDtrueSet to false to short-circuit the hook before input is read
PROMPT_SCANNER_MODEobserveobserve audits silently; warn warns; ask/block use host-specific enforcement or fall back to warn; deny maps to block
PROMPT_SCANNER_SCAN_MODEstandardScan strength passed to scan-prompt: fast / standard / strict
PROMPT_SCANNER_TIMEOUT10Scanner timeout in seconds

Environment variables override Hermes/OpenClaw capability configuration. The host Agent reads them when it loads the plugin, so restart the Agent process after changing them.

Scanner verdict deny describes the risk severity; hook policy block controls whether the current adapter attempts enforcement.

Security Events and Observability

Every scan follows the existing prompt_scan Security Event path. Events contain the source, verdict, summary, threat type, confidence, and sanitized rule or ML findings. They do not contain the raw prompt text.

Host hooks remain fail-open on scanner errors: an error verdict is audited but is not used to block the underlying operation.

Observability uses the existing trace context and input hash to correlate telemetry with the Security Event instead of storing another copy of finding details.