The PII Detection Guardrail is a built-in guardrail you can use detect PII (Personally Identifiable Information) in the input of your Agents. This is useful for applications where you don’t want to allow PII to be sent to the LLM.

Basic Usage

To provide your Agent with the PII Detection Guardrail, you need to import it and pass it to the Agent using the pre_hooks parameter:
from agno.guardrails import PIIDetectionGuardrail
from agno.agent import Agent
from agno.models.openai import OpenAIChat

agent = Agent(
    name="Privacy-Protected Agent",
    model=OpenAIChat(id="gpt-5-mini"),
    pre_hooks=[PIIDetectionGuardrail()],
)

PII fields

The default list of PII fields handled by the guardrail are:
  • Social Security Numbers (SSNs)
  • Credit Card Numbers
  • Email Addresses
  • Phone Numbers
You can also select which specific fields you want to detect. For example, we can disable the Email check by doing this:
guardrail = PIIDetectionGuardrail(
    enable_email_check=False,
)

Custom PII fields

You can also extend the list of PII fields handled by the guardrail by adding your own own custom PII patterns. For example, we can add a custom PII pattern for bank account numbers:
guardrail = PIIDetectionGuardrail(
    custom_patterns={
        "bank_account_number": r"\b\d{10}\b",
    }
)
Notice that providing custom PII patterns via the 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 the mask_pii parameter to True:
guardrail = PIIDetectionGuardrail(
    mask_pii=True,
)
This will mask all the PII in the input with asterisk characters. For example, if you are checking for emails, the string joe@example.com, will be masked as **************.

Developer Resources