Skip to main content

PII anonymizer as a LLM proxy

Project description

AnonTex

AnonTex is a privacy-first experimental LLM proxy that anonymizes Personally Identifiable Information (PII) before forwarding requests to the OpenAI Completion API. It is designed to be compatible with the /v1/chat/completions endpoint, making it a drop-in proxy with minimal integration effort.

⚠️ Note: This is an experimental project. Use with caution in production environments.


✨ Features

  • Acts as a transparent proxy for OpenAI's chat completion endpoint.
  • Automatically anonymizes user input using PII detection.
  • Compatible with OpenAI clients, such as the OpenAI Python SDK and LangChain.
  • Redis-backed for entity management and fast caching.

📦 Installation

Install via pip:

pip install anontex

Note: Redis is a required external dependency for caching and PII management. Make sure you have Redis running locally or remotely.


🚀 Usage

Once installed and configured, AnonTex runs a proxy server compatible with OpenAI’s Chat Completion API.

🔁 Example with curl

curl --request POST \
  --url http://localhost:8000/v1/chat/completions \
  --header 'Authorization: Bearer YOUR-OPENAI-API-KEY' \
  --header 'Content-Type: application/json' \
  --data '{
    "model": "gpt-4o-mini",
    "messages": [
      {
        "role": "system",
        "content": "You are a helpful assistant."
      },
      {
        "role": "user",
        "content": "Hello! My name is John Smith"
      }
    ]
  }'

🐍 Example with OpenAI Python SDK

from openai import OpenAI

client = OpenAI(
    base_url="http://localhost:8000/v1",
    api_key="YOUR-OPENAI-API-KEY"
)

response = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "My email is john@example.com."}
    ]
)

print(response.choices[0].message.content)

🔗 Example with LangChain

from langchain.chat_models import ChatOpenAI
from langchain.schema import HumanMessage

chat = ChatOpenAI(
    openai_api_key="YOUR-OPENAI-API-KEY",
    openai_api_base="http://localhost:8000/v1"
)

messages = [HumanMessage(content="My phone number is 123-456-7890.")]
response = chat(messages)
print(response.content)

⚙️ Configuration

Running Locally

Start the proxy via CLI:

anontex run

CLI Options

  • --host: Server host (default: 0.0.0.0)
  • --port: Server port (default: 8000)
  • --config: Path to configuration file (default: spacy engine configs)
  • --log-level: Logging level (default: info)

Config File (Optional)

You can pass settings via a YAML config file. Read the following documentation to customize the config file.

This project uses the presidio-analyzer Python package as an entity detector. You can use the default config file without specifying a custom file or point to a presidio-analyzer supported config file.

.env File (Optional)

Additional configurations can be done via environment variables in a .env file. If .env is not set, default values will be used. Read the following documentation to customize the .env file.


🐳 Docker Deployment

You can deploy AnonTex with Docker using Docker Compose.

Clone repo:

git clone https://github.com/ChamathKB/AnonTex

Run:

docker compose up -d

🚧 Limitations & Future Improvements

  • ❌ No support for multi-turn PII tracking (PII memory is per-message only).
  • 🔗 Only supports OpenAI API compatible endpoints.
  • 🌐 Limited language support (primarily English).
  • 📈 Planned support for:
    • Multi-turn entity memory
    • Custom anonymization rules
    • Model switching and vendor abstraction
    • Analytics & tracing integration

🤝 Contributing

Pull requests are welcome! For major changes, please open an issue first to discuss what you’d like to change.


📄 License

This project is licensed under the Apache 2.0 License.


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

anontex-0.2.4.tar.gz (16.1 kB view details)

Uploaded Source

Built Distribution

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

anontex-0.2.4-py3-none-any.whl (17.5 kB view details)

Uploaded Python 3

File details

Details for the file anontex-0.2.4.tar.gz.

File metadata

  • Download URL: anontex-0.2.4.tar.gz
  • Upload date:
  • Size: 16.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.11.11 Linux/6.8.0-57-generic

File hashes

Hashes for anontex-0.2.4.tar.gz
Algorithm Hash digest
SHA256 98d53cb84c4d251fd5e31e37df0f1333b4fa908120326dd11652210ae4bbdbbe
MD5 2a7151aa89e00c08e9ed782b35dc5dd7
BLAKE2b-256 8875be0ab3c463cf0d07f1e4a04a4e30dbb543e81e997e4a98cdee46d9366607

See more details on using hashes here.

File details

Details for the file anontex-0.2.4-py3-none-any.whl.

File metadata

  • Download URL: anontex-0.2.4-py3-none-any.whl
  • Upload date:
  • Size: 17.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.11.11 Linux/6.8.0-57-generic

File hashes

Hashes for anontex-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 d4118b1ce3f91a9532ea1ea253122f62190969c659ca46edc7dc722e559d9f4e
MD5 fa55a873acb153fcf6e63a0206c87108
BLAKE2b-256 91b80d8d801961ed2c6fbb8a0ff2fcaaf02be82f187b1379eb80990baaffdecb

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