Skip to main content

OpenAI Agents SDK: Tonic Textual

PII detection and redaction tools and guardrails for the OpenAI Agents SDK, powered by Tonic Textual.

Tonic Textual is a transformer-based PII engine supporting 46+ entity types across 50+ languages. This package provides:

  • Function tools that let agents actively redact PII from text, JSON, HTML, and binary files
  • An input guardrail that blocks user messages containing PII before they reach the LLM
  • An output guardrail that catches PII in agent responses before they reach the user

Installation

pip install openai-agents-tonic-textual

Authentication

All functions read from the TONIC_TEXTUAL_API_KEY environment variable by default:

export TONIC_TEXTUAL_API_KEY="your-textual-api-key"

You can also pass api_key= explicitly to any function if you prefer.

Quick Start

Tools (agent actively calls redaction)

from agents import Agent, Runner
from openai_agents_tonic_textual import textual_tools

agent = Agent(
    name="PII Redactor",
    instructions="Use the available tools to redact PII from any input.",
    tools=textual_tools(),
)

result = Runner.run_sync(agent, "Redact: John Smith lives at 123 Main St")
print(result.final_output)

Input Guardrail (block PII before it reaches the LLM)

from agents import Agent, Runner, InputGuardrailTripwireTriggered
from openai_agents_tonic_textual import textual_input_guardrail

agent = Agent(
    name="Safe Assistant",
    instructions="You are a helpful assistant.",
    input_guardrails=[textual_input_guardrail()],
)

try:
    result = Runner.run_sync(agent, "My SSN is 123-45-6789")
except InputGuardrailTripwireTriggered as e:
    info = e.guardrail_result.output.output_info
    print(f"PII detected! Redacted: {info['redacted_text']}")

Output Guardrail (catch PII in agent responses)

from agents import Agent, Runner, OutputGuardrailTripwireTriggered
from openai_agents_tonic_textual import textual_output_guardrail

agent = Agent(
    name="Safe Assistant",
    instructions="You are a helpful assistant.",
    output_guardrails=[textual_output_guardrail()],
)

try:
    result = Runner.run_sync(agent, "Tell me about John Smith")
except OutputGuardrailTripwireTriggered as e:
    info = e.guardrail_result.output.output_info
    print(f"PII in output! Redacted: {info['redacted_text']}")

Both Guardrails

from openai_agents_tonic_textual import textual_input_guardrail, textual_output_guardrail

agent = Agent(
    name="Fully guarded assistant",
    instructions="You are a helpful assistant.",
    input_guardrails=[textual_input_guardrail()],
    output_guardrails=[textual_output_guardrail()],
)

Available Tools

Tool Description
redact_text Redact PII from plain text
redact_json Redact PII from JSON strings, preserving structure
redact_html Redact PII from HTML content, preserving markup
redact_file Redact PII from binary files (PDF, JPG, PNG, CSV, TSV)
extract_entities Extract PII entities as a JSON array (detection only, no modification)
list_pii_types List all 46+ PII entity types Tonic Textual can detect

Configuration

PII Handling Modes

tools = textual_tools(
    generator_default="Synthesis",  # "Off", "Redaction", or "Synthesis"
    generator_config={
        "NAME_GIVEN": "Synthesis",
        "EMAIL_ADDRESS": "Redaction",
        "PHONE_NUMBER": "Off",
    },
)
Mode Behavior
Off PII is detected but left unchanged
Redaction PII is replaced with entity type labels (e.g., [NAME_GIVEN])
Synthesis PII is replaced with realistic synthetic values

Self-Hosted Deployments

tools = textual_tools(base_url="https://textual.your-company.com")

Guardrail Entity Filtering

Only trigger guardrails for specific PII types:

# Works the same for both input and output guardrails
input_guard = textual_input_guardrail(
    entities=["US_SSN", "CREDIT_CARD"],  # Only block SSNs and credit cards
)

output_guard = textual_output_guardrail(
    entities=["US_SSN", "CREDIT_CARD"],
)

Self-Correcting Error Messages

The tools include built-in format detection. If an agent sends JSON to redact_text, the tool returns an error message naming the correct tool (redact_json). This enables agents to self-correct without human intervention.

Metadata

Release files for openai-agents-tonic-textual 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-tonic-textual 0.1.0
File Size Uploaded
openai_agents_tonic_textual-0.1.0.tar.gz 7.1 kB Details

Built distribution (wheel)

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

Total release size: 15.1 kB

Release files / openai_agents_tonic_textual-0.1.0.tar.gz

Download URL openai_agents_tonic_textual-0.1.0.tar.gz
Size 7.1 kB
Tags Source
SHA-256 checksum
How to use checksums
997aa8f40b3027f6be12a418e3f90e518201fdb1b5a2485fef19b47bde6638fc
BLAKE2b-256 checksum
How to use checksums
1dd0d66c8c199d448d9bd009e9fbe6a2a81aae4e76458753bc132f8a66a493b7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 23, 2026.

Transparency log

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

Download URL openai_agents_tonic_textual-0.1.0-py3-none-any.whl
Size 7.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1894ae202c1b6157de8da17c90471c5976d795126e3b9061a345062baa21fd86
BLAKE2b-256 checksum
How to use checksums
1fc8d085760f83a84a8548cb29fdd69f6760dfaeb0e8ef7f5021f9fbb1281173
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 23, 2026.

Transparency log

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