no_pii()
Guard that detects and handles Personally Identifiable Information.
Usage
no_pii(
*,
patterns=None,
action="rewrite",
)Detects email addresses, phone numbers, SSNs, and credit card numbers by default. Can be extended with custom regex patterns.
Parameters
patterns: list[str] | None = None-
Additional regex patterns to detect. Each should match PII strings.
action: str = "rewrite"-
What to do when PII is found:
"rewrite"(replace with placeholders) or"block"(reject the message entirely).
Returns
Guard- A configured PII detection guard.
Examples
bot = tb.ChatBot().guardrail(tb.no_pii())
bot = tb.ChatBot().guardrail(tb.no_pii(action="block"))