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. Getting Started:

    • Ensure you have a virtual environment with Python 3.7+
    • Install all development dependencies:
    pip install -e ".[dev]"
    
    • Install other dependencies:
    pip install -r requirements.txt
    
  3. 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
  4. Testing:

    python -m unittest discover -v
    
  5. Documentation:

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

    pip install -e ".[dev]"
    
  7. 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.5.tar.gz (408.5 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.5-py3-none-any.whl (389.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: llmshield-0.0.5.tar.gz
  • Upload date:
  • Size: 408.5 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.5.tar.gz
Algorithm Hash digest
SHA256 61b1c2a82aac1e0b7eb94416676cd4d94959f3be1dcc46b496de55715e3052cc
MD5 8bf3a6d03acb8a6f54a00962c382d8f5
BLAKE2b-256 e2e8372f0b83b7a651704dcbf6e459594107d9ee57e27e692d35e67c0f5d8cc0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: llmshield-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 389.1 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.5-py3-none-any.whl
Algorithm Hash digest
SHA256 d6a5ccfc33061d620fe88b7bff550a9cf0af984a255e0af6d7c54c89b7bd37f8
MD5 6c0788e5c32e566499abc89ebc73e82d
BLAKE2b-256 0f93b8073a215a3dcd13215f1e05676e4433507a762ef6c7269a695a7362d460

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