# 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[​](#parameters "Direct link to Parameters")

See plugin [common configurations](https://docs.api7.ai/apisix/reference/plugin-common-configurations.md) for configuration options available to all plugins.

* match\_all\_roles

  boolean

  default: `false`

  ***

  If true, validate messages from all roles. If false, validate the message from `user` role only.

* match\_all\_conversation\_history

  boolean

  default: `false`

  ***

  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 is `user`; the plugin does not search backward for an earlier user message.

  This option does not apply to Responses API requests because `instructions` and `input` are parallel fields rather than conversation history.

* allow\_patterns

  array\[string]

  default: `[]`

  ***

  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 `input` array 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

  array\[string]

  default: `[]`

  ***

  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_patterns` and `deny_patterns` are configured, the plugin first ensures that at least one `allow_patterns` is 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

  string

  default: `skip`

  valid value:

  `skip`, `warn`, or `error`

  ***

  Behavior when the plugin receives a request it cannot inspect, such as non-AI traffic on a Consumer binding. With `skip`, the request passes unchecked. With `warn`, it passes unchecked and a warning is logged. With `error`, 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

  integer

  default: `67108864`

  valid value:

  greater than or equal to 1

  ***

  Maximum 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.
