Skip to main content
Use PIIDetectionGuardrail to reject requests containing PII or replace detected values with masked placeholders.
This example catches InputCheckError around print_response(), but Agno v2.7.2 converts that guardrail exception into a run with RunStatus.error. The source therefore prints false success messages for blocked inputs. Use the status-checking pattern in the PII Detection guide instead.
pii_detection.py

Run the Example

1

Set up your virtual environment

2

Install dependencies

3

Export your OpenAI API key

4

Use run status checks

Add from agno.run import RunStatus. Replace each try/except InputCheckError block with response = agent.run(...), then treat response.status == RunStatus.error as blocked.
5

Run the example

Save the code above as pii_detection.py, then run:
Full source: cookbook/02_agents/08_guardrails/pii_detection.py