Skip to main content

Automatic PII masking for OpenAI and Anthropic SDKs

Project description

Armos

PII never reaches your LLM. One line of code.

Armos wraps the OpenAI and Anthropic SDKs to automatically detect and mask personally identifiable information (PII) before it leaves your server — and restore the real values in the response. Your application code changes by exactly one word.

License: MIT Python 3.9+ PyPI version GitHub Stars


The problem

Every time your application calls an LLM, it sends raw text to a third-party server. If a user's message contains their name, Aadhaar number, email, PAN card, or credit card — that data leaves your infrastructure.

This matters for:

  • Healthcare apps — patient names, dates of birth, medical IDs
  • Fintech apps — PAN, Aadhaar, bank details
  • Customer support tools — names, emails, phone numbers, addresses
  • Any app where users type free text that gets sent to OpenAI or Anthropic

Most teams know this is a risk. Few have time to build a proper masking layer before shipping. Armos is that layer, pre-built.


How it works

How Armos works

Detection runs entirely on your machine. Presidio + spaCy analyse the text locally. No data is sent to any Armos server — there is no Armos server. The vault (token ↔ real value map) lives in your process memory, or optionally in your own Redis instance.


Why Armos over alternatives?

vs. building your own: A custom masking layer takes weeks to build correctly and months to handle edge cases. Armos is a pip install.

vs. LLM Guard: LLM Guard focuses on prompt injection and toxicity — not PII masking. Different problem.

vs. Presidio directly: Presidio detects PII but doesn't handle tokenization, vault management, or SDK integration. Armos wraps all of that.

Indian PII first-class: Aadhaar and PAN detection built in. No competitor handles Indian identifiers reliably.


Quickstart

Install

pip install armos

For Redis-backed persistence across requests:

pip install armos[redis]

Note: On first use, download the spaCy language model:

python -m spacy download en_core_web_lg

OpenAI

# Before
from openai import OpenAI
client = OpenAI()

# After — one import added, one word changed
from openai import OpenAI
from armos import ArmosOpenAI

client = ArmosOpenAI(OpenAI())

# Everything else is identical
response = client.chat.completions.create(
    model="gpt-4o",
    messages=[{
        "role": "user",
        "content": "Summarise the case for patient John Smith, Aadhaar 2345 6789 0123"
    }]
)

# Real values are restored in the response automatically
print(response.choices[0].message.content)

Anthropic

from anthropic import Anthropic
from armos import ArmosAnthropic

client = ArmosAnthropic(Anthropic())

message = client.messages.create(
    model="claude-sonnet-4-6",
    max_tokens=1024,
    messages=[{
        "role": "user",
        "content": "Patient John Smith, DOB 12/04/1982, PAN ABCDE1234F"
    }]
)

print(message.content[0].text)  # real values restored

With Redis (persistent vault across requests)

# Token mappings survive across processes and requests
client = ArmosOpenAI(OpenAI(), store="redis", redis_url="redis://localhost:6379")
client = ArmosAnthropic(Anthropic(), store="redis", redis_url="redis://localhost:6379")

# Custom TTL (default: 24 hours)
client = ArmosOpenAI(OpenAI(), store="redis", redis_url="redis://localhost:6379", vault_ttl=3600)

Standalone (any LLM or framework)

from armos import Armos

guard = Armos()

result = guard.mask("Patient John Smith, Aadhaar 2345 6789 0123, email john@hospital.com")
print(result.text)
# → "Patient [PII:NAME:a1b2c3d4], Aadhaar [PII:AADHAAR:b2c3d4e5], email [PII:EMAIL:e5f6g7h8]"

print(result.has_pii)  # True

restored = guard.demask(result.text)
print(restored)
# → "Patient John Smith, Aadhaar 2345 6789 0123, email john@hospital.com"

What gets detected

Entity Token Example
Person name [PII:NAME:…] John Smith
Email address [PII:EMAIL:…] john@hospital.com
Phone number [PII:PHONE:…] +91 98765 43210
Aadhaar number [PII:AADHAAR:…] 2345 6789 0123
PAN card [PII:PAN:…] ABCDE1234F
Credit / debit card [PII:CARD:…] 4111 1111 1111 1111
IP address [PII:IP:…] 192.168.1.100
API keys & secrets [PII:APIKEY:…] sk-abc123… / AKIA… / ghp_…

Token design

Tokens are deterministic and normalisation-aware:

"john smith"  →  [PII:NAME:a1b2c3d4]  ← stored: "john smith"
"John Smith"  →  [PII:NAME:a1b2c3d4]  ← same token, vault unchanged
"JOHN SMITH"  →  [PII:NAME:a1b2c3d4]  ← same token, vault unchanged

All casing variants of the same name map to one token. The LLM sees one consistent entity across a conversation — not three different people. De-masking restores the first-seen value.


Vault options

Option Default Use when
In-memory Armos() Single request or single process
Redis Armos(store="redis", redis_url="redis://…") Multi-turn conversations, multiple workers, or across requests

In-memory vault is zero configuration and the default. Redis vault persists token mappings so a token created in request 1 can be de-masked in request 5.


v1 limitations

  1. Streaming not supportedstream=True passes through without masking. (v1.1)
  2. Async clients not supportedAsyncOpenAI, AsyncAnthropic pass through without masking. (v1.1)
  3. OpenAI Responses API not interceptedclient.responses.create() passes through. (v1.1)
  4. Embeddings not maskedclient.embeddings.create() sends text as-is. (v1.1)
  5. Indian name accuracyen_core_web_lg is trained on English text; Indian names have lower recall than Western names. Fine-tuning planned for v2.
  6. Casing: first-seen wins — De-masking always restores the first-seen casing of an entity. Use consistent casing in your prompts for exact restoration.
  7. Token length[PII:NAME:a1b2c3d4] is 18 chars vs John (4 chars). Near context-window limits this may push content over. Rare in practice.

Contributing

Armos is open source and MIT licensed. Issues and pull requests welcome.

git clone https://github.com/armos-ai/armos-python
cd armos-python
pip install -e ".[dev,all]"
python -m spacy download en_core_web_lg
pytest tests/ -v

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

armos-0.1.7.tar.gz (494.0 kB view details)

Uploaded Source

Built Distribution

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

armos-0.1.7-py3-none-any.whl (17.5 kB view details)

Uploaded Python 3

File details

Details for the file armos-0.1.7.tar.gz.

File metadata

  • Download URL: armos-0.1.7.tar.gz
  • Upload date:
  • Size: 494.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.6

File hashes

Hashes for armos-0.1.7.tar.gz
Algorithm Hash digest
SHA256 ddd7edb1c15fae05ba83e2ff3ffcf67cfaa7504bb79b7e3bd0fdc69b7efaa68d
MD5 3990f4855bb6d220470c8f2ca615f7bf
BLAKE2b-256 911f40add76f768b4601bcf4b809c0e74d9b2a6c5ab1b31b2561eadecb8253fa

See more details on using hashes here.

File details

Details for the file armos-0.1.7-py3-none-any.whl.

File metadata

  • Download URL: armos-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 17.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.6

File hashes

Hashes for armos-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 260cfa86e31b3ddf8fef92c0c8f254351b80be8a94f93950080f997b34a39751
MD5 acdb820d3c55a11683c7ea726eb239fc
BLAKE2b-256 4abe4a079b81aaa26ecd639b422101d073c21ebe1194d8b9f0dba7aa6926705d

See more details on using hashes here.

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