Skip to main content

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-filter model 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

  1. before_iteration() — Creates a fresh PiiStore, redacts all text content in user/system messages
  2. finalize_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 library
  • nanobot-ai (optional extra) — NanoBot AgentHook framework

Related

License

MIT

Metadata

Release files for nanobot-privacy-filter-hook 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nanobot-privacy-filter-hook 0.1.0
File Size Uploaded
nanobot_privacy_filter_hook-0.1.0.tar.gz 6.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for nanobot-privacy-filter-hook 0.1.0
File Interpreter ABI Platform
nanobot_privacy_filter_hook-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 9.9 kB

Release files / nanobot_privacy_filter_hook-0.1.0.tar.gz

Download URL nanobot_privacy_filter_hook-0.1.0.tar.gz
Size 6.1 kB
Tags Source
SHA-256 checksum
How to use checksums
55046690120650b5a47c03b6e71dd3db7c817ffc34ae552dbbe42a1fa16aeab7
BLAKE2b-256 checksum
How to use checksums
25c7cf32d91c1bbcee621e22dab7a4a7aac00d9b60b77445f2a9621b31458058
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release files / nanobot_privacy_filter_hook-0.1.0-py3-none-any.whl

Download URL nanobot_privacy_filter_hook-0.1.0-py3-none-any.whl
Size 3.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
751778d27bd51cf91dafdd6479c3d63eb0f51df0500474e7ad03db8ada3f4215
BLAKE2b-256 checksum
How to use checksums
bf05b7345b3129ee90d829c073211d98b56be4813b511f9b3b65cf60b6f92083
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page