Skip to main content

Privacy layer for AI prompts

Project description

🔐 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

  1. User Input: "My Aadhaar is 1234 5678 1234."
  2. Mask (PrivyLayer): "My Aadhaar is ⟦PII_AADHAAR_x1⟧." (Validates checksum internally).
  3. AI Model: Processes the masked text.
  4. Restore (PrivyLayer): Swaps the token back for the original value.
  5. 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)

from privylayer import protect

text = "My phone is 9876543210 and Aadhaar is [Aadhaar Redacted]"
# find_p analyzes the text and returns masked version, context, and metadata
mask, context, seen = protect.find_p(text)

print(mask)
# Output: My phone is ⟦PII_PHONE_x1⟧ and Aadhaar is ⟦PII_AADHAAR_x2⟧

🔓 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.

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

privylayer-0.2.4.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

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

privylayer-0.2.4-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file privylayer-0.2.4.tar.gz.

File metadata

  • Download URL: privylayer-0.2.4.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for privylayer-0.2.4.tar.gz
Algorithm Hash digest
SHA256 033d2e36d086f3112d488ec2e1dd4531c874733f3f59c5522ca835e8e0a83e3f
MD5 0a0383ca6f28e00ed454e4787f434011
BLAKE2b-256 d343996fa1000e4be0d971f211b47f32a9c1ef1d48b34f8400ab0416f7cfdfa2

See more details on using hashes here.

File details

Details for the file privylayer-0.2.4-py3-none-any.whl.

File metadata

  • Download URL: privylayer-0.2.4-py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for privylayer-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 ebb0b9c9bb5e0f81835d117c34782b891a0d030358017cfc76b634fc8241cced
MD5 75b84849ef9c9470391c9ec97a2d9fd1
BLAKE2b-256 fc3d461c3b0bff2e8dcca4d1ca93b73ebf7634ea91980f41af6c6e3b0dfe6e65

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