Shields your confidential data from third party LLM providers
Project description
llmshield
Overview
llmshield is a lightweight and dependency-free Python library designed for high-performance cloaking and uncloaking of sensitive information in prompts and responses from Large Language Models (LLMs). It provides robust entity detection and protection where data privacy and security are paramount.
The aim is to be extremely accurate, using a combination of list-based, rule-based, pattern-based, and probabilistic approaches.
Key Features
-
🔒 Secure Entity Detection: Identifies and protects sensitive information including:
- Personal names
- Email addresses
- Phone numbers
- IP addresses
- URLs
- Credit card numbers
- Reference/Order numbers
- And more...
-
🚀 High Performance: Optimised for minimal latency in LLM interactions
-
🔌 Zero Dependencies: Pure Python implementation with no external requirements
-
🛡️ Bidirectional Protection: Secures both prompts and responses
-
🎯 Flexible Integration: Works with any LLM provider
Installation
pip install llmshield
Quick Start
from llmshield import LLMShield
# Basic usage - Manual LLM integration
shield = LLMShield()
# Cloak sensitive information
cloaked_prompt, entity_map = shield.cloak("Hi, I'm John Doe (john.doe@example.com)")
print(cloaked_prompt) # "Hi, I'm <PERSON_0> (<EMAIL_0>)"
# Send to your LLM...
llm_response = your_llm_function(cloaked_prompt)
# Uncloak the response
original_response = shield.uncloak(llm_response, entity_map)
# Direct LLM integration
def my_llm_function(prompt: str) -> str:
# Your LLM API call here
return response
shield = LLMShield(llm_func=my_llm_function)
response = shield.ask("Hi, I'm John Doe (john.doe@example.com)")
Configuration
Delimiters
You can customise the delimiters used to wrap protected entities:
shield = LLMShield(
start_delimiter='[[', # Default: '<'
end_delimiter=']]' # Default: '>'
)
The choice of delimiters should align with your LLM provider's training. Different providers may perform better with different delimiter styles.
LLM Function Integration
Provide your LLM function during initialization for streamlined usage:
shield = LLMShield(llm_func=your_llm_function)
Best Practices
- Consistent Delimiters: Use the same delimiters across your entire application
- Error Handling: Always handle potential ValueError exceptions
- Entity Mapping: Store entity maps securely if needed for later uncloaking
- Input Validation: Ensure prompts are well-formed and grammatically correct
Requirements
- Python 3.7+
- No additional dependencies
- Officially supports English and Spanish texts only.
- May work with other languages with lower accuracy and potential PII leakage.
Performance
llmshield is optimized for minimal latency:
- Compiled regex patterns
- Efficient entity detection algorithms
- No external API calls
- Minimal memory footprint
Security Considerations
- Entity maps contain sensitive information and should be handled securely
- Consider your LLM provider's security guidelines when choosing delimiters
- Regular updates are recommended for the latest security features
Contributing
Contributions are welcome! Please follow these guidelines:
-
Code Quality:
- Follow black and isort formatting
- Add tests for new features
- Maintain zero dependencies
- Use British English across naming and documentation
-
Testing:
python -m unittest discover -v
-
Documentation:
- Update docstrings
- Keep README.md current
- Add examples for new features
License
GNU APGLv3 License - See LICENSE.txt file for details
Support
- GitHub Issues: Report bugs or request features
- Documentation: Full documentation
Notable Uses
llmshield is currently used by:
## Building
rm -rf build/ dist/ *.egg-info/
python setup.py build
python setup.py sdist bdist_wheel
pip uninstall llmshield -y
pip install -e .
pip install dist/llmshield-*.whl
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 llmshield-0.0.1.tar.gz.
File metadata
- Download URL: llmshield-0.0.1.tar.gz
- Upload date:
- Size: 51.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8c0a7d72654542cdea3303fe58609f2f45388f3c322790d56b57d2e81cd0dcaf
|
|
| MD5 |
b48f8218c93b38ecbc52bf9b9ff00fea
|
|
| BLAKE2b-256 |
d04a85abd6e67d60b2f1745584f36d1517b4c33d9df8b9bb59a81b7a3d8c3fec
|
File details
Details for the file llmshield-0.0.1-py3-none-any.whl.
File metadata
- Download URL: llmshield-0.0.1-py3-none-any.whl
- Upload date:
- Size: 35.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2493262eb06d86badedfbbd8015d499d529dda86285350f35fa4909c3ac27c76
|
|
| MD5 |
2c20bdeaaf393a814b1d0d74f0b1d376
|
|
| BLAKE2b-256 |
cd519f022f0f5025bc63754223e8408e64b600a804cb8277fe678ef3c76d76d4
|