keyword_block()

Guard that blocks messages containing any of the specified keywords.

Usage

Source

keyword_block(
    keywords,
    *,
    case_sensitive=False,
    phase=GuardPhase.BOTH,
)

Parameters

keywords: list[str]

List of words or phrases to block.

case_sensitive: bool = False

Whether matching should be case-sensitive.

phase: GuardPhase = GuardPhase.BOTH
When to apply: input, output, or both.

Returns

Guard
A configured keyword blocking guard.

Examples

bot = tb.ChatBot().guardrail(
    tb.keyword_block(["password", "secret key", "api_key"])
)