A proxy server to filter Personally Identifiable Information (PII) from requests and responses to a Large Language Model (LLM).
- Github repository: https://github.com/doublej/pii-filter-proxy/
- Documentation https://doublej.github.io/pii-filter-proxy/
This proxy sits between your application and an LLM API (like OpenAI's). It intercepts the requests, filters the prompt for any banned words or phrases, and then forwards the request to the LLM. It also filters the response from the LLM before sending it back to your application.
The filtering is configured through a YAML file located at ~/.llm_filter/filters.yaml.
-
Clone the repository:
git clone https://github.com/doublej/pii-filter-proxy.git cd pii-filter -
Install the dependencies:
uv sync --extra dev
Create a file at ~/.llm_filter/filters.yaml with the following structure:
replacements:
"John Doe": "[REDACTED]"
"john.doe@example.com": "[REDACTED]"
banned:
- "secret"
- "password"
flags:
case_sensitive: false
log_filtered: trueThe proxy supports the following environment variables:
OPENAI_API_KEY: OpenAI API key for upstream requestsOPENAI_ENDPOINT: Custom OpenAI endpoint (defaults to https://api.openai.com)PII_FILTER_DOTENV_PATH: Path to your project's .env file (optional)
You can configure the proxy to use your project's environment variables in several ways:
# Start the proxy
uvicorn pii_filter.proxy.server:app
# Configure it to use your project's .env file
curl -X POST http://127.0.0.1:8000/api/env \
-H "Content-Type: application/json" \
-d '{"path": "/path/to/your/project/.env"}'To start the proxy server:
uvicorn pii_filter.proxy.server:app --reloadThis will start the proxy on http://127.0.0.1:8000.
If no filters are configured, the proxy will return a 400 Bad Request error.
POST /v1/chat/completions- OpenAI-compatible chat completions with PII filteringPOST /api/env- Set .env file path:{"path": "/path/to/.env"}GET /api/config- Get current filtering configurationPOST /api/config- Update filtering configuration
You can also manage the configuration through the CLI:
# Show the current configuration
python -m pii_filter_proxy.cli config --show
# Add a banned word
python -m pii_filter_proxy.cli config --add-banned "new secret"
# Add a replacement
python -m pii_filter_proxy.cli config --add-replacement "Jane Doe" "[REDACTED]"This project uses pre-commit to enforce code style and quality. To set it up, run:
pre-commit installRepository initiated with fpgmaas/cookiecutter-uv.