PII redaction guardrails for OpenAI Agents SDK
Project description
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-filterHuggingFace 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 libraryopenai-agents(optional extra) — OpenAI Agents SDK
Related
- Core library: privacy-filter
- NanoBot integration: nanobot-privacy-filter-hook
- OpenAI Agents docs: https://openai.github.io/openai-agents-python/
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 openai_agents_privacy_filter-0.1.0.tar.gz.
File metadata
- Download URL: openai_agents_privacy_filter-0.1.0.tar.gz
- Upload date:
- Size: 7.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 |
9a338f86e32b520c46487f2729099a8269fdc419f2529d258fc1228756e9218b
|
|
| MD5 |
0047966ec9fc5490356a6d88d7eb6f76
|
|
| BLAKE2b-256 |
af5fa0b0937a640997342bbce12f7750ff2e8dae80a6adb67932e6b84f926bc4
|
File details
Details for the file openai_agents_privacy_filter-0.1.0-py3-none-any.whl.
File metadata
- Download URL: openai_agents_privacy_filter-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.1 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 |
d92d31d79a4f04c0954a4b4bd8e571a6e4f83506a989e17a2127d9a381268912
|
|
| MD5 |
b211f4853663da3daca3b1ecab12a65a
|
|
| BLAKE2b-256 |
88644aa6f186eb69053f747e9d6220beae50cdc9c15ddc473dc2fd2fc7fc7c2d
|