Privacy guardrail for AI applications — mask PII before it reaches any LLM
Project description
glasslm
Privacy guardrail for AI applications. Mask sensitive data before sending to any LLM, restore it from the response.
Install
pip install glasslm
Usage
Basic Masking
from glasslm import mask, unmask
# Mask PII from text
result = mask("Email me at user@example.com, my key is sk-abc123xyz789")
print(result.masked_text)
# "Email me at [[EMAIL_1]], my key is [[API_KEY_1]]"
print(result.masked_items)
# [MaskedItem(id='email_1', original='user@example.com', ...)]
# Restore the original from a response
response = "I'll contact [[EMAIL_1]] about the [[API_KEY_1]] integration."
restored = unmask(response, result.masked_items)
print(restored)
# "I'll contact user@example.com about the sk-abc123xyz789 integration."
With an LLM (OpenAI example)
from glasslm import mask, unmask
import openai
client = openai.OpenAI(api_key="your-openai-key")
user_input = "My API key is sk-abc123... please help me debug."
# 1. Mask
result = mask(user_input)
# 2. Send masked text to LLM
response = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": result.masked_text}]
)
raw_reply = response.choices[0].message.content
# 3. Restore
final_reply = unmask(raw_reply, result.masked_items)
print(final_reply)
What gets detected
| Type | Examples |
|---|---|
api_key |
sk-..., pk-..., OpenAI/Anthropic keys |
email |
user@example.com |
phone |
+1 (555) 123-4567 |
ssn |
123-45-6789 |
credit_card |
4111 1111 1111 1111 (Luhn validated) |
access_token |
JWT, Bearer tokens |
private_key |
PEM-encoded RSA keys |
cloud_credential |
AWS Access Keys (AKIA...) |
database_url |
mongodb://..., postgresql://... |
ip_address |
IPv4 and IPv6 |
name |
John Smith (context-aware) |
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
glasslm-0.1.0.tar.gz
(6.0 kB
view details)
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 glasslm-0.1.0.tar.gz.
File metadata
- Download URL: glasslm-0.1.0.tar.gz
- Upload date:
- Size: 6.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fcc8d8b9aa8bae0b69143aa04ded0b65496517b4b3006f34a92423722c5db6f9
|
|
| MD5 |
2ffd4ad86a0314b08a2e6b18f52fc8aa
|
|
| BLAKE2b-256 |
2b767607ceb9f03e7a6eb9a567a108f1b576416f3d0f24ccf6299860cdd9cb0c
|
File details
Details for the file glasslm-0.1.0-py3-none-any.whl.
File metadata
- Download URL: glasslm-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4cabf5457d6956c9b6524a13f1ebc0843c6cc83a71a219d69bde7189611fe457
|
|
| MD5 |
1daaceda5f0fb2e87728fe073004d468
|
|
| BLAKE2b-256 |
d12191921a4b1ad9ca23c0b1f499e7b6fa0444e0cf26e965a8e679bd3c4b0266
|