Skip to main content

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:
    • Proper nouns (Persons, Places, Organisations, Concepts)
    • Locators (Email addresses, URLs)
    • Numbers (Phone numbers, Credit card numbers)

Additional PII types are in development.

  • 🚀 High Performance: Optimised for minimal latency in LLM interactions
  • 🔌 Zero Dependencies: Pure Pythonic implementation with no external requirements
  • 🛡️ End-to-End Protection: Cloaks and uncloaks both prompts and responses
  • 🎯 Flexible Integration: Works directly with your existing LLM function.

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(prompt="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

  1. Consistent Delimiters: Use the same delimiters across your entire application
  2. Error Handling: Always handle potential ValueError exceptions
  3. Entity Mapping: Store entity maps securely if needed for later uncloaking
  4. 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.

Support

Contributing

Contributions are welcome! Please follow these guidelines:

  1. Recommended IDE Development Packages:

    • Black
    • Isort
    • Markdownlint
  2. Code Quality and Formatting Guidelines:

    • Follow black and isort rules
    • Add tests for new features
    • Do not break existing tests (unless justifying the change)
    • Maintain zero (non-development) dependencies (non-negotiable)
    • Use British English in all naming and documentation
  3. Testing:

    python -m unittest discover -v
    
  4. Documentation:

    • Update docstrings
    • Keep README.md current
    • Add examples for new features
  5. Build for development

pip install -e ".[dev]"
  1. Build and publish
python -m build
python -m twine upload dist/*

Note: You will need to have a PyPI account and be authenticated.

License

GNU APGLv3 License - See LICENSE.txt file for details

Notable Uses

llmshield is currently used by:

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

llmshield-0.0.2.tar.gz (402.9 kB view details)

Uploaded Source

Built Distribution

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

llmshield-0.0.2-py3-none-any.whl (387.3 kB view details)

Uploaded Python 3

File details

Details for the file llmshield-0.0.2.tar.gz.

File metadata

  • Download URL: llmshield-0.0.2.tar.gz
  • Upload date:
  • Size: 402.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for llmshield-0.0.2.tar.gz
Algorithm Hash digest
SHA256 882c243c8a24f44988bd1eab3c1ecdbf6277c01588e6b2e3dbf9c005d82e2a8d
MD5 44123837c7ef9bdf6bcb34094e034686
BLAKE2b-256 e0c44492e5458fd0d32815328e9b9343e568285348f6be907bbc3687aa1ed996

See more details on using hashes here.

File details

Details for the file llmshield-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: llmshield-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 387.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for llmshield-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ffc724f1271386673f4eaaa1c392a11dcb9c9098436df38b1a09f2683a38f447
MD5 f796bd438d27d0ae55b0ac3ffef1edc5
BLAKE2b-256 af3007e0d19d5fce1a4ef642e66b8e499e6e71322c69a3e83fcbb3485cb9d932

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