Pattern matching does not establish that an input contains no PII. Add custom patterns or separate controls for formats your application must cover.
Basic Usage
To provide your Agent with the PII Detection Guardrail, you need to import it and pass it to the Agent using thepre_hooks parameter:
PII fields
The built-in checks match these formats:- US Social Security numbers written as
123-45-6789 - 16-digit credit card numbers, with optional spaces or hyphens between groups
- Email addresses
- 10-digit phone numbers, with optional spaces, periods, or hyphens
Custom PII fields
You can also extend the list of PII fields handled by the guardrail by adding your own custom PII patterns. For example, we can add a custom PII pattern for bank account numbers:custom_patterns parameter will extend, not override, the default list of PII fields. You can stop checking for default PII fields by setting the enable_ssn_check, enable_credit_card_check, enable_email_check, and enable_phone_check parameters to False.
Masking PII
By default, the PII Detection Guardrail will raise an error if it detects any PII in the input. However, you can mask the PII in the input instead of raising, by setting themask_pii parameter to True:
joe@example.com will be masked as ***************.