Branch Status
| main | update-yml-comment |
|---|---|
A local Python implementation demonstrating how to build an isolated, offline privacy guardrail that intercepts and flags Personal Identifiable Information (PII) using Guardrails AI and Microsoft Presidio.
- Offline Mode: Configured for standalone local execution (
use_local=True) to avoid network requests and 401 authentication errors. - Direct Architecture Imports: Upgraded to the modern explicit
guardrails_aipackage namespace format. - Noisy Warning Suppression: Internal filters silence system event loop warnings and multi-language dictionary mismatched logs (
presidio-analyzer).
This project utilizes modern Guardrails plugins that strictly require Python 3.10, 3.11, or 3.12 (Requires-Python <4, >=3.10).
If your machine defaults to an older version (e.g., Python 3.9), upgrade using Homebrew before creating the environment:
#mac
brew install python@3.13Initialize a fresh environment tied explicitly to a compatible Python runtime:
# Remove an older environment if necessary
rm -rf .venv
# Build and activate using a compatible binary
python3.11 -m venv .venv
source .venv/bin/activateUpgrade your installation tools and pull down the explicit standalone PII detector distribution:
python -m pip install --upgrade pip
pip install guardrails-ai-detect-piiCreate a file named demo_pii.py and populate it with the optimized solution code below.
and run the application inside your terminal:
python demo_pii.pyDuring the creation of this project, several configuration boundaries were identified and corrected:
command not found: pip- Cause: Your machine's PATH environmental paths were disconnected from global executables.
- Fix: Switched to executing pip explicitly as a python core module:
python3 -m pip install <package>.
Could not find a version that satisfies the requirement- Cause: Attempting installation on an unsupported Python system version (e.g., Python < 3.10).
- Fix: Recreated the environment using a targeted
python3.11or higher.
TypeError: Guard.use() got an unexpected keyword argument- Cause: Config keys passed inside the wrapper rather than the child object.
- Fix: Instantiated the validator instance directly inside the method call:
Guard().use(DetectPII(args...)).
401: Remote Inference Unauthorized- Cause: Library defaulting to cloud hosting requiring cloud API keys.
- Fix: Passed
use_local=Truedirectly into the class initializer to keep text matching private on the local computer.
WARNING:presidio-analyzer:Recognizer not added...- Cause: Internal parser trying to bind multilingual profiles (Spanish, Italian, Polish) to an English-only operating system footprint.
- Fix: Added runtime overrides using Python's
loggingsystem to filter tracking events lower thanERROR.
This project includes an automated GitHub Actions CI workflow to verify your PII guardrails on every code push or pull request to the main branch.
Because it uses local inference, it runs completely free without needing cloud API keys.
Create a file at .github/workflows/ci.yml like ci.yml
- When code is pushed, GitHub provisions a clean Linux runner.
- It enforces the required Python 3.11 environment.
- It installs the exact standalone
guardrails-ai-detect-piipackage. - It executes
demo_pii.pyto ensure your privacy validators compile and run seamlessly without breaking the build pipeline.
This architecture functions as a security gatekeeper within your development workflow. When integrated into a Pull Request pipeline, it prevents unsafe code or sensitive configurations from being merged into production branches.
In Python, any unhandled error or an explicit sys.exit(1) call flags the terminal environment with a non-zero exit status. Because GitHub Actions monitors runtime exit codes, a triggered Guardrail exception will intentionally crash the runner stage.
When this happens:
- The Execute PII Guardrail Script pipeline step immediately turns red.
- GitHub applies a status check block on the Pull Request interface.
- The "Merge pull request" button is completely locked out, preventing developers from introducing data leaks into protected environments.
You can view a simulated breakdown of how GitHub traps these code exceptions in the repository action log:
👉 View Sample Failed Pipeline Run (Sample link demonstrating failed security workflow execution logs)
