A library for making anonymized calls to LLM APIs
Project description
BlindLLM
BlindLLM is a Python library that provides a secure way to interact with LLM APIs by automatically anonymizing sensitive information in prompts and de-anonymizing the responses. It supports multiple LLM services including OpenAI, Mistral, and Claude.
Features
- Automatic anonymization of sensitive data (names, emails, organizations, phone numbers, etc.)
- Support for multiple LLM services:
- OpenAI (GPT-4o, GPT-4, GPT-3.5-turbo)
- Mistral AI
- Anthropic's Claude
- Simple, unified interface for all supported services
- Automatic de-anonymization of responses
Installation
pip install .
Requirements
- Python 3.8 or higher
- API keys for the services you plan to use
- text_anonymizer library
Quick Start
from blindllm import BlindLLM
# Initialize with your chosen service
llm = BlindLLM(
service="openai", # or "mistral" or "claude"
model="gpt-4", # model name for the chosen service
api_key="your-api-key"
)
# Make a call - get all information including anonymized data
prompt = "John Smith from Acme Corp (email: john.smith@acme.com) asked about the project status."
result = llm.call(prompt)
# Access all available information
print(result['anonymized_prompt']) # The anonymized version of your prompt
print(result['anonymized_response']) # The raw response from the LLM
print(result['response']) # The final de-anonymized response
print(result['anonymization_map']) # The mapping of tokens to original values
Supported Services and Models
OpenAI
- gpt-4o
- gpt-4
- gpt-3.5-turbo
- And other available OpenAI chat models
Mistral
- mistral-large-latest
- mistral-medium-latest
- mistral-small-latest
- mistral-tiny-latest
Claude
- claude-3-5-sonnet-20241022
- claude-3-opus-20240229
- claude-3-sonnet-20240229
- claude-3-haiku-20240307
- And other available Claude models
How It Works
-
Anonymization: When you make a call, BlindLLM uses the
text_anonymizerlibrary to anonymize sensitive information in your prompt by replacing it with tokens (e.g., [ENTITY_PERSON_1], [ENTITY_EMAIL_1], [ENTITY_ORG_1]). -
API Call: The anonymized prompt is sent to the chosen LLM service.
-
De-anonymization: The response from the LLM is automatically de-anonymized by replacing the tokens with the original sensitive information.
Example
from blindllm import BlindLLM
llm = BlindLLM(
service="openai",
model="gpt-4",
api_key="your-openai-api-key"
)
# Example of what happens behind the scenes:
# 1. Your prompt:
prompt = "John Smith from Acme Corp (email: john.smith@acme.com) asked about the project status."
# 2. Anonymized before sending to API:
# result['anonymized_prompt'] will be something like:
# "[ENTITY_PERSON_1] from [ENTITY_ORG_1] (email: [ENTITY_EMAIL_1]) asked about the project status."
# 3. Raw LLM response with anonymized tokens:
# result['anonymized_response'] contains the direct response from the LLM
# 4. Final de-anonymized response:
# result['response'] contains the response with original names restored
# 5. Mapping information:
# result['anonymization_map'] contains:
# {
# "[ENTITY_PERSON_1]": "John Smith",
# "[ENTITY_ORG_1]": "Acme Corp",
# "[ENTITY_EMAIL_1]": "john.smith@acme.com"
# }
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
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 blindllm-0.1.0.tar.gz.
File metadata
- Download URL: blindllm-0.1.0.tar.gz
- Upload date:
- Size: 7.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8d2c5659d232e1804accc050f757cc9feac3dd90f7254c2cdbac321081272f96
|
|
| MD5 |
0b1d3fd4fd412f336e19652a1240137f
|
|
| BLAKE2b-256 |
82648989e665b74a845465529f79decdcbfc311cc3f93e163222e1a7ee4c2ce6
|
File details
Details for the file blindllm-0.1.0-py3-none-any.whl.
File metadata
- Download URL: blindllm-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f184ca2a44d59945dbc69b8102eb0ff3d3da3504edb361b8c2264a6b681cff19
|
|
| MD5 |
c97994f01a7504b22e719a381ce9583a
|
|
| BLAKE2b-256 |
c172e1d74d5f6baa41e3f20519f16b11e0bf4d4bb8944a220b70105120733ed8
|