🔐 PrivyLayer
Privacy layer for AI systems — protect sensitive data before it reaches the LLM.
🚀 Overview
PrivyLayer is a lightweight Python library designed to act as a secure buffer between user input and AI models. It detects sensitive information (PII), replaces it with secure tokens, and restores the original data after the AI response—ensuring zero data exposure to third-party providers.
⚡ Why PrivyLayer?
Modern AI systems often process raw user data, which may contain:
- Identity: Aadhaar, PAN
- Contact: Phone numbers, Emails
- Finance: Bank details, IFSC codes
PrivyLayer solves this by introducing a reversible masking system, allowing AI to understand context without ever seeing the actual private values.
🧠 How It Works
- User Input: "My Aadhaar is 1234 5678 1234."
- Mask (PrivyLayer): "My Aadhaar is
⟦PII_AADHAAR_x1⟧." (Validates checksum internally). - AI Model: Processes the masked text.
- Restore (PrivyLayer): Swaps the token back for the original value.
- Final Output: Securely displayed to the user.
✨ Features
- 🔍 Advanced Detection: Uses optimized patterns for PII.
- ✅ Aadhaar Validation: Now includes checksum verification to notify if an Aadhaar number is real or fake.
- 🔁 Reversible Masking: Maintain full context without data loss.
- 🧠 Smart Tokenization: Structured
⟦PII_TYPE_ID⟧format for easy LLM processing. - ⚡ Fast & Lightweight: Minimal overhead for real-time applications.
- 🔒 Privacy First: No data is stored or sent to any external server.
📦 Installation
pip install privylayer
🛠️ Usage
🔐 Protect (Mask data)
import privylayer
text = "My phone is 9876543210 and Aadhaar is 987654321096"
# find_p analyzes the text and returns masked version, context, and metadata
mask, context, seen = privylayer.mask(text)
print(mask)
🔓 Restore (Unmask data)
from privylayer import restore
original = restore(masked_response, context)
print(original)
# Output: My phone is 9876543210 and Aadhaar is [Aadhaar Redacted]
🧩 Supported Data Types (India-Specific)
- 📱 Phone numbers
- 📧 Email addresses
- 🪪 Aadhaar numbers (With Checksum Validation)
- 🧾 PAN numbers
- 🏦 IFSC codes
🛡️ Aadhaar Checksum Validation
The latest version of PrivyLayer automatically validates the integrity of Aadhaar numbers using the Verhoeff algorithm.
- Note: The library will print a system message indicating whether the detected Aadhaar is Real or Fake based on the checksum, ensuring higher data quality before masking.
🚀 Roadmap
- AI-based entity and name detection
- Risk scoring system for data sensitivity
- Open for all over the world for major countries with specfic detection
- API Gateway integration
⚠️ Limitations
While PrivyLayer provides a robust security buffer, users should be aware of the following technical boundaries:
No Official PAN/IFSC Verification: The library detects PAN cards and IFSC codes using structural pattern matching (Regex). It does not connect to government databases or banking APIs to verify if the identity or bank branch actually exists.
Aadhaar Checksum Only: For Aadhaar, the library performs a Verhoeff algorithm checksum validation. This confirms if the number is mathematically valid (Real vs. Fake format), but it does not perform biometric or OTP-based authentication.
Regex-Based Detection: Since the core engine relies on sophisticated regular expressions, it may occasionally struggle with high-accuracy name detection if the names are common dictionary words.
Context Dependency: The restore() function requires the original context object generated during the protect() phase. If this context is lost or corrupted, the masked data cannot be recovered.
No Global Storage: PrivyLayer is entirely stateless. While this is a security feature, it means you are responsible for securely managing the mapping context within your own application environment. We always look forward to provide Ultimate Privacy
📄 License
MIT License
👨💻 Author
Built by Nithish 🚀 Portfolio | GitHub
🌟 Vision: Making AI safe for everyone by protecting sensitive data at the source.
Metadata
Release files for privylayer 0.2.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| privylayer-0.2.6.tar.gz | 4.4 kB | Without provenance | Details for privylayer-0.2.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| privylayer-0.2.6-py3-none-any.whl | Python 3 | none | any | Details for privylayer-0.2.6-py3-none-any.whl |
Total release size: 9.3 kB
Release files / privylayer-0.2.6.tar.gz
| Download URL | privylayer-0.2.6.tar.gz |
|---|---|
| Size | 4.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0c4c36b4744fda0e0f443a8e8378c5173ed8c4aa6aec10eaba0662f945b7c5c4
|
|
BLAKE2b-256 checksum How to use checksums |
fffe9b56574be9a753ecc87a081d62db8ca5713d52d1ca0ed19e678af778d295
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.10
|
Release files / privylayer-0.2.6-py3-none-any.whl
| Download URL | privylayer-0.2.6-py3-none-any.whl |
|---|---|
| Size | 4.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
14c98ef06b09b9c915f52bf3699ee488b8df29aa5ed767098f80616f738d9472
|
|
BLAKE2b-256 checksum How to use checksums |
18acaaf42e69c19ea4ae1a7412e9aef75f7de28ed0b3f3b461080140a052ee04
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.10
|
Security for privylayer 0.2.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.