NanoBot AgentHook that redacts PII before LLM inference
Project description
nanobot-privacy-filter-hook
PII redaction guardrail for NanoBot. Automatically redact personally identifiable information before LLM calls and restore original values in responses.
Features
- Automatic PII detection — Uses the
openai/privacy-filtermodel locally - Pre/post processing — Redact before LLM sees text, unredact in the response
- Message format support — Works with string and OpenAI vision-style list content
- Configurable — Adjust confidence thresholds and filter by entity type
Installation
pip install nanobot-privacy-filter-hook
Requires:
- Python 3.11+
nanobot-ai(for AgentHook interface)
Quick Start
from nanobot_hook import PrivacyFilterHook
# Create hook
hook = PrivacyFilterHook(min_score=0.8)
# Register with NanoBot's CompositeHook
from nanobot.agent.hook import CompositeHook
composite = CompositeHook([hook, other_hook])
# Pass composite to your NanoBot agent runner
How It Works
before_iteration()— Creates a freshPiiStore, redacts all text content in user/system messagesfinalize_content()— Restores original values from placeholders in the LLM response
Configuration
from nanobot_hook import PrivacyFilterHook
hook = PrivacyFilterHook(
min_score=0.8, # Minimum confidence threshold (0.0-1.0)
entity_types=None, # Filter to specific entities (None = all)
cache_dir=None, # Custom HuggingFace cache directory
)
Supported Entity Types
| Entity | Placeholder | Description |
|---|---|---|
private_email |
[EMAIL_N] |
Email addresses |
private_person |
[PERSON_N] |
Person names |
private_phone |
[PHONE_N] |
Phone numbers |
private_address |
[ADDRESS_N] |
Physical addresses |
private_url |
[URL_N] |
URLs |
private_date |
[DATE_N] |
Dates |
account_number |
[ACCOUNT_N] |
Account numbers |
secret |
[SECRET_N] |
Passwords, API keys |
Example: Full Integration
from nanobot.agent.hook import CompositeHook, AgentHookContext
from nanobot_hook import PrivacyFilterHook
# Create and register hook
pii_hook = PrivacyFilterHook(min_score=0.9)
composite = CompositeHook([pii_hook])
# The hook automatically processes messages before each LLM iteration
# and unredacts content before returning to the user
Dependencies
privacy-filter— Core PII detection librarynanobot-ai(optional extra) — NanoBot AgentHook framework
Related
- Core library: privacy-filter
- OpenAI Agents integration: openai-agents-privacy-filter
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nanobot_privacy_filter_hook-0.1.0.tar.gz.
File metadata
- Download URL: nanobot_privacy_filter_hook-0.1.0.tar.gz
- Upload date:
- Size: 6.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
55046690120650b5a47c03b6e71dd3db7c817ffc34ae552dbbe42a1fa16aeab7
|
|
| MD5 |
a3a2a260ecd7edebdfd23429c6707079
|
|
| BLAKE2b-256 |
25c7cf32d91c1bbcee621e22dab7a4a7aac00d9b60b77445f2a9621b31458058
|
File details
Details for the file nanobot_privacy_filter_hook-0.1.0-py3-none-any.whl.
File metadata
- Download URL: nanobot_privacy_filter_hook-0.1.0-py3-none-any.whl
- Upload date:
- Size: 3.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
751778d27bd51cf91dafdd6479c3d63eb0f51df0500474e7ad03db8ada3f4215
|
|
| MD5 |
cf8e52f0f4a65241b79cb92f8f3e59af
|
|
| BLAKE2b-256 |
bf05b7345b3129ee90d829c073211d98b56be4813b511f9b3b65cf60b6f92083
|