piihush
Fast PII and secret masking for AI applications. A Rust extension for Python that removes sensitive data from your text before it reaches an external model provider.
The problem
─AI applications pass a lot of data to external providers: documents, user messages, tool results and logs. That data often holds email addresses, card numbers and API keys. piihush masks them first, and it's fast enough to run on every chunk, without adding noticeable latency to a pipeline.
Quick start
─pip install "piihush[llm]"
from piihush.llm import PrivateChat
chat = PrivateChat("openai", model="gpt-4.1-mini")
reply = chat.send("Write a reminder to email jane@example.com")
# The provider receives: Write a reminder to email [EMAIL_1]
# You receive: a reply containing jane@example.comWhat it does
─Masking
Detects emails, phones, cards, IBANs, API keys, JWTs, private keys, passwords and more. Linear-time matching means crafted input can't trigger catastrophic backtracking.
PrivacyGuard
Swaps values for tokens such as [EMAIL_1], so a model works without seeing them, then restores the real values in its reply.
PrivateChat
Wraps a chat with OpenAI, Claude, Gemini, DeepSeek, Grok, Ollama, llama.cpp or any OpenAI-compatible service. The provider only sees tokens.
Name detection
An optional BERT model finds names and places in free text, and runs on your own machine after one model download.
LLM detection
An optional LLM can flag extra values, with the rules always running alongside it. It can only add masking, never remove it.
Built for pipelines
Releases the GIL, runs batches across all CPU cores, and works with threads, fork() and pickling.
Where to use it
─Accuracy
─Measured on 3,000 English records of the independent ai4privacy pii-masking-400k dataset, kept apart from the data used to build the rules.
| Tool | PII masked | Ordinary words kept | Time per record |
|---|---|---|---|
| piihush NerMasker | 69.7% | 96.6% | About 160 ms |
| Presidio | 64.8% | 94.8% | 15 ms |
| piihush Masker | 48.6% | 98.2% | About 20 µs |
| scrubadub | 13.8% | 98.3% | 1.2 ms |
| pyveil | 13.1% | 100% | 0.3 ms |
| pii-veil | 10.7% | 100% | 0.2 ms |
No PII tool catches everything, so piihush works best as one layer of a privacy strategy, alongside access controls and review for highly sensitive data.