Skip to main content

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nanobot_privacy_filter_hook-0.1.0.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nanobot_privacy_filter_hook-0.1.0-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

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

Hashes for nanobot_privacy_filter_hook-0.1.0.tar.gz
Algorithm Hash digest
SHA256 55046690120650b5a47c03b6e71dd3db7c817ffc34ae552dbbe42a1fa16aeab7
MD5 a3a2a260ecd7edebdfd23429c6707079
BLAKE2b-256 25c7cf32d91c1bbcee621e22dab7a4a7aac00d9b60b77445f2a9621b31458058

See more details on using hashes here.

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

Hashes for nanobot_privacy_filter_hook-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 751778d27bd51cf91dafdd6479c3d63eb0f51df0500474e7ad03db8ada3f4215
MD5 cf8e52f0f4a65241b79cb92f8f3e59af
BLAKE2b-256 bf05b7345b3129ee90d829c073211d98b56be4813b511f9b3b65cf60b6f92083

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page