A library to protect your prompts.
Project description
PromptShield (pshield)
A Python library that automatically detects and replaces sensitive information in text with placeholders.
Features
- 🔒 Detects 20+ entity types (emails, phones, cards, names, locations, etc.)
- 🌍 Multi-language support with automatic placeholder translation
- 🎯 Uses spaCy NER for accurate name/location detection
- 🔄 Consistent placeholders across documents
Installation
pip install pshield
python -m spacy download en_core_web_sm
Quick Start
from pshield import PromptShield
shield = PromptShield()
protected = shield.protect("John sent $50 to jane@example.com")
# Output: "[NAME_1] sent [AMOUNT_1] to [EMAIL_1]"
Usage
# Disable translation (keep placeholders in English)
protected = shield.protect("Your text", translate=False)
# Multi-language example
shield.protect("Bob a envoyé 50 USD à bob@example.com")
# Returns: "[NOM_1] a envoyé [MONTANT_1] à [E-MAIL_1]"
Supported Entities
Personal: Names, emails, phones, usernames
Financial: Credit cards, CVV, expiry dates, amounts
Location: Places, coordinates, IP addresses
Digital: URLs, JWT tokens, Bitcoin/Ethereum addresses
Other: Dates, memory sizes, alphanumeric codes
API
PromptShield(nlp=None)
nlp: Optional spaCy model (defaults toen_core_web_sm)
protect(text: str, translate: bool = True) -> str
Replaces sensitive entities with placeholders.
text: Input text to protecttranslate: Translate placeholders to detected language (default:True)
Requirements
Python 3.9+, spaCy >= 3.7.0, langdetect >= 1.0.9, deep-translator >= 1.11.4
Links
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
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 pshield-1.0.0.tar.gz.
File metadata
- Download URL: pshield-1.0.0.tar.gz
- Upload date:
- Size: 10.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
47f56bd659e551e437d5adbc794f4413adb65ed8c3cab7c8ef4a36f6090c39a2
|
|
| MD5 |
1d6163f17b53de5298ced7f404cd83e3
|
|
| BLAKE2b-256 |
cae933dcb119db1413c5f18af300cdc605b5515990e87763f9abc0f76c2fde35
|
File details
Details for the file pshield-1.0.0-py3-none-any.whl.
File metadata
- Download URL: pshield-1.0.0-py3-none-any.whl
- Upload date:
- Size: 11.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
95384651a22f1ed3bc15dd6e79c608b01292a6e238a3f5e6da2e336474488588
|
|
| MD5 |
56eb079ae231dc89685514714914b6bc
|
|
| BLAKE2b-256 |
91c5d2035ed0f3fc453efcc696e4c9a10ccee99d9906ae1bca133372d45ff5c6
|