LangChain integration for Tonic Textual PII redaction
Project description
langchain-textual
PII redaction tools for LangChain, powered by Tonic Textual.
Strip names, emails, addresses, and other sensitive data from text, JSON, HTML, and files before they hit your LLM — or on the way back out. Drop them into any LangChain chain or agent as standard tools.
Installation
pip install langchain-textual
Quick start
export TONIC_TEXTUAL_API_KEY="your-api-key"
from langchain_textual import TonicTextualRedactText
tool = TonicTextualRedactText()
tool.invoke("My name is John Smith and my email is john@example.com.")
# "My name is [NAME_GIVEN_xxxx] [NAME_FAMILY_xxxx] and my email is [EMAIL_ADDRESS_xxxx]."
Tools
| Tool | Input | Use for |
|---|---|---|
TonicTextualRedactText |
Plain text string | Raw text, .txt file contents |
TonicTextualRedactJson |
JSON string | Raw JSON, .json file contents |
TonicTextualRedactHtml |
HTML string | Raw HTML, .html/.htm file contents |
TonicTextualRedactFile |
File path | PDFs, images (JPG, PNG), CSVs, TSVs |
TonicTextualPiiTypes |
None | List all supported PII entity types |
Text
from langchain_textual import TonicTextualRedactText
tool = TonicTextualRedactText()
tool.invoke("My name is John Smith and my email is john@example.com.")
# "My name is [NAME_GIVEN_xxxx] [NAME_FAMILY_xxxx] and my email is [EMAIL_ADDRESS_xxxx]."
JSON
from langchain_textual import TonicTextualRedactJson
tool = TonicTextualRedactJson()
tool.invoke('{"name": "John Smith", "email": "john@example.com"}')
# '{"name": "[NAME_GIVEN_xxxx] [NAME_FAMILY_xxxx]", "email": "[EMAIL_ADDRESS_xxxx]"}'
HTML
from langchain_textual import TonicTextualRedactHtml
tool = TonicTextualRedactHtml()
tool.invoke("<p>Contact John Smith at john@example.com</p>")
# "<p>Contact [NAME_GIVEN_xxxx] [NAME_FAMILY_xxxx] at [EMAIL_ADDRESS_xxxx]</p>"
Files
from langchain_textual import TonicTextualRedactFile
tool = TonicTextualRedactFile()
tool.invoke({"file_path": "/path/to/scan.pdf"})
# "/path/to/scan_redacted.pdf"
tool.invoke({"file_path": "/path/to/photo.jpg", "output_path": "/tmp/redacted.jpg"})
# "/tmp/redacted.jpg"
For .txt, .json, and .html/.htm files, read the file contents and pass them to the corresponding text, JSON, or HTML tool instead.
Configuration
All tools share the same configuration options.
Synthesis mode — replace PII with realistic fake data instead of placeholders:
tool = TonicTextualRedactText(generator_default="Synthesis")
tool.invoke("Contact Jane Doe at jane.doe@example.com.")
# "Contact Maria Chen at maria.chen@gmail.com."
Per-entity control — set handling per PII type with generator_config:
tool = TonicTextualRedactText(
generator_default="Off",
generator_config={
"NAME_GIVEN": "Synthesis",
"NAME_FAMILY": "Synthesis",
"EMAIL_ADDRESS": "Redaction",
},
)
tool.invoke("Contact Jane Doe at jane.doe@example.com.")
# "Contact Maria Chen at chen@[EMAIL_ADDRESS_xxxx]."
Use TonicTextualPiiTypes to list all supported entity type names:
from langchain_textual import TonicTextualPiiTypes
TonicTextualPiiTypes().invoke("")
# "NUMERIC_VALUE, LANGUAGE, MONEY, ..., EMAIL_ADDRESS, NAME_GIVEN, NAME_FAMILY, ..."
Self-hosted deployment:
tool = TonicTextualRedactText(tonic_textual_base_url="https://textual.your-company.com")
Explicit API key (instead of env var):
tool = TonicTextualRedactText(tonic_textual_api_key="your-api-key")
Using with a LangChain agent
Every tool in this package is a standard LangChain tool, so they work anywhere tools do. Give your agent whichever combination it needs:
from langchain_textual import (
TonicTextualRedactText,
TonicTextualRedactJson,
TonicTextualRedactFile,
)
from langchain_openai import ChatOpenAI
from langgraph.prebuilt import create_react_agent
llm = ChatOpenAI(model="gpt-4o-mini")
tools = [TonicTextualRedactText(), TonicTextualRedactJson(), TonicTextualRedactFile()]
agent = create_react_agent(llm, tools)
Development
# install dependencies
uv sync --group dev --group test --group lint --group typing
# install pre-commit hooks (auto-runs ruff on each commit)
uv tool install pre-commit
pre-commit install
# run unit tests
make test
# run integration tests (requires TONIC_TEXTUAL_API_KEY)
make integration_tests
# lint & format
make lint
make format
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 langchain_textual-0.1.1.tar.gz.
File metadata
- Download URL: langchain_textual-0.1.1.tar.gz
- Upload date:
- Size: 133.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3c31dcf512a32a04b869a5bcaa55aa5d55dbf0be8eac6bb724031e60d13c3a28
|
|
| MD5 |
46fe9f1150552f5d124c2b3c47129eda
|
|
| BLAKE2b-256 |
9d541569922ec6b2ca1d6c4713deeb4e654128c29a8d3d094d7d874dab74f4f5
|
Provenance
The following attestation bundles were made for langchain_textual-0.1.1.tar.gz:
Publisher:
publish.yml on TonicAI/langchain-textual
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
langchain_textual-0.1.1.tar.gz -
Subject digest:
3c31dcf512a32a04b869a5bcaa55aa5d55dbf0be8eac6bb724031e60d13c3a28 - Sigstore transparency entry: 1123236911
- Sigstore integration time:
-
Permalink:
TonicAI/langchain-textual@eaa99837ab56786320babb6181f304a94dcd9033 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/TonicAI
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@eaa99837ab56786320babb6181f304a94dcd9033 -
Trigger Event:
release
-
Statement type:
File details
Details for the file langchain_textual-0.1.1-py3-none-any.whl.
File metadata
- Download URL: langchain_textual-0.1.1-py3-none-any.whl
- Upload date:
- Size: 8.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
563f43e63c05d6c55387401d5b42ba279a27603b7a1ae62ac1408ceecba53566
|
|
| MD5 |
c7641a27b24bda50214d9246f17d7102
|
|
| BLAKE2b-256 |
0f24cfd306ec2151557688d347a57b583485f63035942a56781729d5524b91ce
|
Provenance
The following attestation bundles were made for langchain_textual-0.1.1-py3-none-any.whl:
Publisher:
publish.yml on TonicAI/langchain-textual
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
langchain_textual-0.1.1-py3-none-any.whl -
Subject digest:
563f43e63c05d6c55387401d5b42ba279a27603b7a1ae62ac1408ceecba53566 - Sigstore transparency entry: 1123236915
- Sigstore integration time:
-
Permalink:
TonicAI/langchain-textual@eaa99837ab56786320babb6181f304a94dcd9033 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/TonicAI
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@eaa99837ab56786320babb6181f304a94dcd9033 -
Trigger Event:
release
-
Statement type: