Skip to main content

openai-agents-privacy-filter

PII redaction guardrails for the OpenAI Agents SDK. Automatically redact personally identifiable information from agent inputs and restore original values in outputs.

Features

  • Input guardrail — Redact PII from user messages before the agent processes them
  • Output guardrail — Restore original values from placeholders in agent responses
  • Local processing — Uses the openai/privacy-filter HuggingFace model (no API calls)
  • Configurable — Adjust confidence thresholds and filter by entity type

Installation

pip install openai-agents-privacy-filter

Requires:

  • Python 3.11+
  • openai-agents (for guardrail interface)

Quick Start

from privacy_filter_openai import PiiInputGuardrail, PiiOutputGuardrail
from agents import Agent, Runner

# Create guardrails
input_guardrail = PiiInputGuardrail(min_score=0.8)
output_guardrail = PiiOutputGuardrail()

# Create agent with PII guardrails
agent = Agent(
    name="PII-Safe Agent",
    instructions="You are a helpful assistant.",
    input_guardrails=[input_guardrail],
    output_guardrails=[output_guardrail],
)

# Run — PII is automatically redacted before LLM and restored after
result = await Runner.run(agent, "My email is alice@example.com")
print(result.final_output)  # "Your email is alice@example.com" (not [EMAIL_1])

How It Works

Input Guardrail

  • Runs before the agent sees the user input
  • Detects PII using the privacy-filter model
  • Replaces PII with placeholders like [EMAIL_1], [PERSON_2]
  • Stores mappings for later restoration

Output Guardrail

  • Runs after the agent generates a response
  • Restores original values from placeholders
  • Returns the unredacted content to the user

Configuration

from privacy_filter_openai import PiiInputGuardrail, PiiOutputGuardrail

input_guardrail = PiiInputGuardrail(
    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
)

output_guardrail = PiiOutputGuardrail()

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

Complete Example

import asyncio
from agents import Agent, Runner
from privacy_filter_openai import PiiInputGuardrail, PiiOutputGuardrail

async def main():
    input_guardrail = PiiInputGuardrail(min_score=0.9)
    output_guardrail = PiiOutputGuardrail()

    agent = Agent(
        name="Assistant",
        instructions="Help the user with their questions.",
        input_guardrails=[input_guardrail],
        output_guardrails=[output_guardrail],
    )

    result = await Runner.run(
        agent,
        "My name is John Doe and my phone is 555-0123"
    )
    print(result.final_output)
    # Output references "John Doe" and "555-0123", not placeholders

if __name__ == "__main__":
    asyncio.run(main())

GuardrailResult Behavior

  • Input guardrail: Returns GuardrailResult(output=redacted_text, triggered=True) — the agent sees redacted text
  • Output guardrail: Returns GuardrailResult(output=unredacted_text, triggered=True) — user sees original values

Dependencies

  • privacy-filter — Core PII detection library
  • openai-agents (optional extra) — OpenAI Agents SDK

Related

License

MIT

Metadata

Release files for openai-agents-privacy-filter 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 openai-agents-privacy-filter 0.1.0
File Size Uploaded
openai_agents_privacy_filter-0.1.0.tar.gz 7.1 kB Details

Built distribution (wheel)

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

Total release size: 12.2 kB

Release files / openai_agents_privacy_filter-0.1.0.tar.gz

Download URL openai_agents_privacy_filter-0.1.0.tar.gz
Size 7.1 kB
Tags Source
SHA-256 checksum
How to use checksums
9a338f86e32b520c46487f2729099a8269fdc419f2529d258fc1228756e9218b
BLAKE2b-256 checksum
How to use checksums
af5fa0b0937a640997342bbce12f7750ff2e8dae80a6adb67932e6b84f926bc4
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 / openai_agents_privacy_filter-0.1.0-py3-none-any.whl

Download URL openai_agents_privacy_filter-0.1.0-py3-none-any.whl
Size 5.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d92d31d79a4f04c0954a4b4bd8e571a6e4f83506a989e17a2127d9a381268912
BLAKE2b-256 checksum
How to use checksums
88644aa6f186eb69053f747e9d6220beae50cdc9c15ddc473dc2fd2fc7fc7c2d
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