Skip to main content

PIIGhost

CI PyPI version Python versions License: MIT Security: bandit Discord

piighost is a Python library that keeps PII (personally identifiable information) from reaching a language model, while keeping the application fully functional.

The library spots PII with detectors (regex, NER, or another LLM) and replaces each value with a stable placeholder, for example john.doe@example.com becomes <<EMAIL:1>>. The model only ever works on de-identified text. When the LLM returns placeholders, piighost puts the real values back in place, the end user sees john.doe@example.com and never notices the de-identification. The same mechanism protects tool-using agents. A tool that needs the real address receives it in clear, while the LLM that decides to call it still sees only <<EMAIL:1>>.

Finally, the library keeps the mapping between a value and its placeholder across the whole conversation. If john.doe@example.com shows up again three messages later, the placeholder stays <<EMAIL:1>>, so the model can follow the thread.

A user chats with an agent: PII values are replaced by placeholders before reaching the model and restored afterwards for the user and for tool calls.

The LLM only sees placeholders. The tool receives the real address, the user gets a clear-text reply, and your agent code stays the same.

[!NOTE] piighost performs reversible de-identification. Because the mapping between a value and its placeholder is kept so the data can be restored, this is pseudonymisation under the GDPR, not permanent anonymisation. The real values stay stored for the duration of the conversation and must be protected accordingly.

Quickstart

uv add piighost

De-identify a text

ExactMatchDetector de-identifies a dictionary of known values without downloading a model.

import asyncio

from piighost.components.detector import ExactMatchDetector
from piighost.pipeline import AnonymizationPipeline

detector = ExactMatchDetector({"John Doe": "PERSON", "john.doe@example.com": "EMAIL"})
pipeline = AnonymizationPipeline(detector)

result = asyncio.run(pipeline.anonymize("Write to John Doe at john.doe@example.com."))
print(result.text)  # Write to <<PERSON:1>> at <<EMAIL:1>>.

Conversations and agents (LangChain)

The middleware wraps a conversational pipeline and handles each agent turn. The LLM only sees placeholders, tools receive the real values, the user gets a clear-text reply.

uv add 'piighost[langchain]'
from langchain.agents import create_agent
from piighost.integrations.langchain import PIIAnonymizationMiddleware

# pipeline: a ThreadAnonymizationPipeline, see the conversation guide
agent = create_agent(
    model="openai:gpt-5.4",
    tools=[send_email],
    middleware=[PIIAnonymizationMiddleware(pipeline=pipeline)],
)

For a real detector, the conversational pipeline and a full LangChain example, see the Quickstart and the LangChain integration.

Documentation

Full documentation

Project

Download files

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

Source Distribution

piighost-1.4.0.tar.gz (3.8 MB view details)

Uploaded Source

Built Distribution

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

piighost-1.4.0-py3-none-any.whl (138.1 kB view details)

Uploaded Python 3

File details

Details for the file piighost-1.4.0.tar.gz.

File metadata

  • Download URL: piighost-1.4.0.tar.gz
  • Upload date:
  • Size: 3.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for piighost-1.4.0.tar.gz
Algorithm Hash digest
SHA256 3e3f98ec609aae38980cc87ba43e098e39a90aac6fcbf901438208c7e5f5c260
MD5 eabb7ba5d29cc7d7e36434ce9d2ac948
BLAKE2b-256 694cbffc0ef5227ec30cef477152784ed74bbaa147352fee73e34909ab1907e1

See more details on using hashes here.

File details

Details for the file piighost-1.4.0-py3-none-any.whl.

File metadata

  • Download URL: piighost-1.4.0-py3-none-any.whl
  • Upload date:
  • Size: 138.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for piighost-1.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 43415c94799d2f9842369e132f9efd83b44a2f8bb1ab7840a17d875e9b6e15a4
MD5 5876609efa7726338696162508cbdefe
BLAKE2b-256 acd6e2666b0738e39836cdd28ca70d03309af4a75e980b69634a9cda95b46d5b

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.4.0 This release

2 files

1.3.0

2 files

1.2.0

2 files

1.1.1

2 files

1.1.0

2 files

1.0.1

2 files

1.0.0

2 files

0.14.0

2 files

0.13.0

2 files

0.12.1

2 files

0.12.0

2 files

0.11.0

2 files

0.10.0

2 files

0.9.1

2 files

0.9.0

2 files

0.8.0

2 files

0.7.0

2 files

0.6.0

2 files

0.5.1

2 files

0.5.0

2 files

0.4.2

2 files

0.4.1

2 files

0.4.0

2 files

0.3.0

2 files

0.2.0

2 files

0.1.0

2 files

Supported by

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