Skip to main content

Haystack integration for Tonic Textual PII detection, transformation, and entity extraction

Project description

textual-haystack

PyPI version License: MIT Python 3.10+

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

textual_haystack-0.1.0.tar.gz (268.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

textual_haystack-0.1.0-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

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

Hashes for textual_haystack-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b0a700c91200de792f043b98d31018fa566fe3819d7649e4107881cc74415a07
MD5 d0eb9167eea0522945fca6fa3f3f7ca0
BLAKE2b-256 2247a1437954a80403f3336879abe3a11d47e193a4d70a9f56606c8d11f3d6dc

See more details on using hashes here.

Provenance

The following attestation bundles were made for textual_haystack-0.1.0.tar.gz:

Publisher: publish.yml on TonicAI/textual-haystack

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file textual_haystack-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for textual_haystack-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 68b385be42e78bea873b9153cb99bba30a8591880c5320bfaf064deabeb5cb05
MD5 3a9a3f5644243582907294bebe590e98
BLAKE2b-256 b6a13883ee88007614ecddaf586effb24331e8cbc869cf512d8e78cc12eb654b

See more details on using hashes here.

Provenance

The following attestation bundles were made for textual_haystack-0.1.0-py3-none-any.whl:

Publisher: publish.yml on TonicAI/textual-haystack

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page