Skip to content

Keyword Filter

Matches specific keywords or regex patterns in user input and performs an action (block, sanitize, log).

Matches specific keywords or regex patterns in user input and performs an action (block, sanitize, log).

The Keyword Filter guard scans messages for specific words, phrases, or regular expressions. It supports three modes:

  • block: Rejects the request if a keyword is found.
  • sanitize: Replaces found keywords with the configured replacement text.
  • log: Only logs the finding without altering the request or blocking it.

Matching can be case-sensitive or insensitive, and you can require matching ‘all’ keywords instead of ‘any’.

FieldTypeDefaultDescription
keywordsarray[]List of keywords or regular expressions to match.
match_modestring"any"Whether to trigger on ‘any’ matched keyword or require ‘all’ to match.
case_sensitivebooleanFalseWhether the matching should be case-sensitive.
actionstring"block"Action to take when triggered (‘block’, ‘sanitize’, ‘log’).
replacementstring"[REDACTED]"Text to replace matched keywords with when action is ‘sanitize’.
use_regexbooleanFalseWhether the keywords should be treated as regular expressions.
scan_input_onlybooleanFalseWhen True, keywords are only matched against the request input. Stream output scanning (stream_blocks) is skipped. Use this for broad patterns that would cause false positives on model output.
# Block Specific Words
type: keyword_filter
config:
keywords:
- secret
- confidential
match_mode: any
action: block
# Sanitize API Keys
type: keyword_filter
config:
keywords:
- sk-[a-zA-Z0-9]{48}
use_regex: true
action: sanitize
replacement: '[API_KEY_REDACTED]'