AI Prompt Guard Configuration
The ai-prompt-guard plugin safeguards prompts to LLM using allow/deny patterns, ensuring only approved inputs pass. It can check the latest message or full history. Configuration covers plugin parameters.
Parameters
See plugin common configurations for configuration options available to all plugins.
match_all_roles
If true, validate messages from all roles. If false, validate the message from
userrole only.match_all_conversation_history
If true, concatenate and check all messages in the conversation history. If false, first select only the final message, then apply
match_all_roles. With the default role setting, the final message is checked only when its role isuser; the plugin does not search backward for an earlier user message.This option does not apply to Responses API requests because
instructionsandinputare parallel fields rather than conversation history.allow_patterns
An array of RegEx patterns that selected text should match. When configured, the combined selected text must match at least one pattern to be considered valid.
In APISIX 3.20.0, string items in an Embeddings
inputarray are joined with spaces and evaluated as one value. A pattern can match within an item or across the inserted space. API7 Enterprise 3.9.23 and 3.10.10 do not inspect Embeddings string arrays.deny_patterns
An array of RegEx patterns that messages should not match. If messages match any of the patterns, the request should be rejected.
If both
allow_patternsanddeny_patternsare configured, the plugin first ensures that at least oneallow_patternsis matched.In APISIX 3.20.0, deny patterns run against the same space-joined Embeddings value as allow patterns. A match anywhere in that combined text rejects the whole batch. API7 Enterprise 3.9.23 and 3.10.10 do not inspect Embeddings string arrays.
fail_mode
valid value:
skip,warn, orerrorBehavior when the plugin receives a request it cannot inspect, such as non-AI traffic on a Consumer binding. With
skip, the request passes unchecked. Withwarn, it passes unchecked and a warning is logged. Witherror, the plugin rejects it with HTTP 400. None of these outcomes means prompt validation succeeded.Introduced in API7 Enterprise 3.9.14 and APISIX 3.18.0.
max_req_body_size
valid value:
greater than or equal to 1Maximum request body size in bytes buffered into memory. Larger request bodies are rejected with HTTP 400 before prompt validation. Introduced in API7 Enterprise 3.9.17 and 3.10.4, and APISIX 3.18.0.