Haystack integration for Tonic Textual PII detection, transformation, and entity extraction
Project description
textual-haystack
PII detection, transformation, and entity extraction components for Haystack, powered by Tonic Textual.
Detect sensitive data in documents, extract the raw entities for auditing or custom logic, or synthesize and tokenize PII before ingestion. Drop these components into any Haystack pipeline.
Installation
pip install textual-haystack
Components
| Component | Purpose |
|---|---|
TonicTextualEntityExtractor |
Extract PII entities with type, value, location, and confidence score |
TonicTextualDocumentCleaner |
Synthesize or tokenize PII in document content |
Quick start
export TONIC_TEXTUAL_API_KEY="your-api-key"
Entity extraction
from haystack.dataclasses import Document
from haystack_integrations.components.tonic_textual import (
TonicTextualEntityExtractor,
)
extractor = TonicTextualEntityExtractor()
result = extractor.run(
documents=[Document(content="My name is John Smith and my email is john@example.com")]
)
for entity in TonicTextualEntityExtractor.get_stored_annotations(result["documents"][0]):
print(f"{entity.entity}: {entity.text} (confidence: {entity.score:.2f})")
# NAME_GIVEN: John (confidence: 0.90)
# NAME_FAMILY: Smith (confidence: 0.90)
# EMAIL_ADDRESS: john@example.com (confidence: 0.95)
Document cleaning
from haystack.dataclasses import Document
from haystack_integrations.components.tonic_textual import (
TonicTextualDocumentCleaner,
)
# Synthesize PII with realistic fakes
cleaner = TonicTextualDocumentCleaner(generator_default="Synthesis")
result = cleaner.run(
documents=[Document(content="Contact John Smith at john@example.com")]
)
print(result["documents"][0].content)
# "Contact Maria Chen at maria.chen@gmail.com"
Per-entity control — mix synthesis and tokenization per PII type:
cleaner = TonicTextualDocumentCleaner(
generator_default="Off",
generator_config={
"NAME_GIVEN": "Synthesis",
"NAME_FAMILY": "Synthesis",
"EMAIL_ADDRESS": "Redaction",
},
)
In a pipeline
from haystack import Pipeline
from haystack.dataclasses import Document
from haystack_integrations.components.tonic_textual import (
TonicTextualDocumentCleaner,
TonicTextualEntityExtractor,
)
pipeline = Pipeline()
pipeline.add_component("cleaner", TonicTextualDocumentCleaner(generator_default="Synthesis"))
pipeline.add_component("extractor", TonicTextualEntityExtractor())
pipeline.connect("cleaner", "extractor")
result = pipeline.run({
"cleaner": {
"documents": [
Document(content="Contact Jane Doe at jane@example.com"),
]
}
})
Configuration
Self-hosted deployment:
extractor = TonicTextualEntityExtractor(
base_url="https://textual.your-company.com"
)
Explicit API key:
from haystack.utils.auth import Secret
extractor = TonicTextualEntityExtractor(
api_key=Secret.from_token("your-api-key")
)
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 textual_haystack-0.1.0.tar.gz.
File metadata
- Download URL: textual_haystack-0.1.0.tar.gz
- Upload date:
- Size: 268.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b0a700c91200de792f043b98d31018fa566fe3819d7649e4107881cc74415a07
|
|
| MD5 |
d0eb9167eea0522945fca6fa3f3f7ca0
|
|
| BLAKE2b-256 |
2247a1437954a80403f3336879abe3a11d47e193a4d70a9f56606c8d11f3d6dc
|
Provenance
The following attestation bundles were made for textual_haystack-0.1.0.tar.gz:
Publisher:
publish.yml on TonicAI/textual-haystack
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
textual_haystack-0.1.0.tar.gz -
Subject digest:
b0a700c91200de792f043b98d31018fa566fe3819d7649e4107881cc74415a07 - Sigstore transparency entry: 1134480551
- Sigstore integration time:
-
Permalink:
TonicAI/textual-haystack@c1ed7a63fbda4b4ed4774908df5cba868d4aa3ed -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/TonicAI
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c1ed7a63fbda4b4ed4774908df5cba868d4aa3ed -
Trigger Event:
release
-
Statement type:
File details
Details for the file textual_haystack-0.1.0-py3-none-any.whl.
File metadata
- Download URL: textual_haystack-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.7 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 |
68b385be42e78bea873b9153cb99bba30a8591880c5320bfaf064deabeb5cb05
|
|
| MD5 |
3a9a3f5644243582907294bebe590e98
|
|
| BLAKE2b-256 |
b6a13883ee88007614ecddaf586effb24331e8cbc869cf512d8e78cc12eb654b
|
Provenance
The following attestation bundles were made for textual_haystack-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on TonicAI/textual-haystack
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
textual_haystack-0.1.0-py3-none-any.whl -
Subject digest:
68b385be42e78bea873b9153cb99bba30a8591880c5320bfaf064deabeb5cb05 - Sigstore transparency entry: 1134480772
- Sigstore integration time:
-
Permalink:
TonicAI/textual-haystack@c1ed7a63fbda4b4ed4774908df5cba868d4aa3ed -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/TonicAI
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c1ed7a63fbda4b4ed4774908df5cba868d4aa3ed -
Trigger Event:
release
-
Statement type: