DSGVO-konformes Erkennen und Ersetzen von PII in LLM-Prompts
Project description
privacy-guard
DSGVO/GDPR-konformes Erkennen und Ersetzen von personenbezogenen Daten (PII) in Text — regel- und musterbasiert, kein ML-Inference zur Laufzeit.
Designed für den Einsatz vor LLM-Prompts: sensitive Daten werden durch stabile, umkehrbare Platzhalter ersetzt und können nach der LLM-Antwort wiederhergestellt werden.
Features
| Typ | Beispiele |
|---|---|
| Namen | „Hans Müller", „Dr. Anna Schmidt" (via spaCy NER) |
| IBAN | DE89 3704 0044 0532 0130 00 (+ ISO 7064 Prüfsumme) |
| Telefon | +49 89 12345678, 0800 123456 |
| kontakt@example.de | |
| Adresse | Hauptstraße 12, 79100 Freiburg |
| Secrets | API-Keys, Tokens, Passwörter (122 Muster) |
- Personen des öffentlichen Lebens (Politiker, CEOs, Prominente) werden nicht maskiert
- Gleicher Originaltext → gleicher Platzhalter (Deduplication)
ScanResult.restore()ersetzt Platzhalter zurück in den LLM-Output
Python-Package
Installation
pip install privacy-guard-scanner
Der Namens-Detektor benötigt zusätzlich ein spaCy-Modell:
pip install "de_core_news_sm @ https://github.com/explosion/spacy-models/releases/download/de_core_news_sm-3.8.0/de_core_news_sm-3.8.0-py3-none-any.whl"
# oder:
python -m spacy download de_core_news_sm
Alle anderen Detektoren (IBAN, Telefon, E-Mail, Adresse, Secrets) funktionieren ohne das Modell.
Schnellstart
from privacy_guard import PrivacyScanner
scanner = PrivacyScanner()
result = scanner.scan(
"Bitte überweise 500 € an Hans Müller, IBAN DE89 3704 0044 0532 0130 00. "
"Rückfragen an h.mueller@example.de oder +49 89 123456."
)
print(result.anonymised_text)
# → "Bitte überweise 500 € an [NAME_1], IBAN [IBAN_1]. Rückfragen an [EMAIL_1] oder [PHONE_1]."
print(result.mapping)
# → {"[NAME_1]": "Hans Müller", "[IBAN_1]": "DE89 3704 0044 0532 0130 00", ...}
# LLM-Antwort wiederherstellen
llm_response = "Vielen Dank, [NAME_1]! Ihre Überweisung von [IBAN_1] wurde verarbeitet."
print(result.restore(llm_response))
# → "Vielen Dank, Hans Müller! Ihre Überweisung von DE89 3704 0044 0532 0130 00 wurde verarbeitet."
Detektoren einzeln steuern
from privacy_guard import PrivacyScanner, PiiType
scanner = PrivacyScanner()
scanner.disable_detector(PiiType.NAME) # Namens-Detektor deaktivieren
scanner.enable_detector(PiiType.NAME) # wieder aktivieren
# Eigene Whitelist-Einträge (werden nicht maskiert)
scanner = PrivacyScanner(extra_whitelist_names=["Erika Musterfrau"])
Nur bestimmte Findings auswerten
secrets = [f for f in result.findings if f.pii_type == PiiType.SECRET]
for s in secrets:
print(f" {s.rule_id}: {s.text!r} (confidence={s.confidence})")
REST-API (Docker)
Das Repo enthält eine FastAPI-Oberfläche, die als Docker-Image bereitgestellt wird.
Schnellstart
docker run -p 8000:8000 <dockerhub-user>/privacy-guard:latest
Oder mit docker compose (startet aus dem geklonten Repo und baut das Image lokal):
docker compose up
Endpunkte
| Methode | Pfad | Beschreibung |
|---|---|---|
GET |
/health |
Liveness-Check |
POST |
/scan |
Text scannen, Findings + anonymisierten Text zurückgeben |
POST |
/anonymize |
Nur anonymisierten Text zurückgeben |
Request-Schema
Beide POST-Endpunkte akzeptieren dasselbe JSON-Schema:
{
"text": "Hans Müller, IBAN DE89370400440532013000",
"detectors": ["IBAN", "EMAIL"],
"whitelist": ["Hans Müller"]
}
| Feld | Typ | Default | Beschreibung |
|---|---|---|---|
text |
string |
— | Zu scannender Text |
detectors |
string[] |
alle | Aktive Detektoren: NAME, IBAN, PHONE, EMAIL, ADDRESS, SECRET |
whitelist |
string[] |
[] |
Namen, die der Namens-Detektor ignorieren soll |
Beispiel
curl -X POST http://localhost:8000/scan \
-H "Content-Type: application/json" \
-d '{"text": "Kontakt: hans@example.de, IBAN DE89370400440532013000", "detectors": ["EMAIL", "IBAN"]}'
{
"anonymised_text": "Kontakt: [EMAIL_1], IBAN [IBAN_1]",
"findings": [
{"start": 9, "end": 25, "text": "hans@example.de", "pii_type": "EMAIL", "confidence": 1.0, "placeholder": "[EMAIL_1]"},
{"start": 32, "end": 54, "text": "DE89370400440532013000", "pii_type": "IBAN", "confidence": 1.0, "placeholder": "[IBAN_1]"}
],
"mapping": {
"[EMAIL_1]": "hans@example.de",
"[IBAN_1]": "DE89370400440532013000"
}
}
Konfiguration
Die API wird über Umgebungsvariablen konfiguriert:
| Variable | Default | Beschreibung |
|---|---|---|
API_KEY |
— | Wenn gesetzt, muss jeder Request den Header X-API-Key: <key> mitschicken |
CORS_ORIGINS |
* |
Erlaubte Origins, kommagetrennt (z.B. https://myapp.example.com) |
# docker-compose.yml
services:
api:
build: .
ports:
- "8000:8000"
environment:
API_KEY: mein-geheimer-key
CORS_ORIGINS: https://myapp.example.com
Lizenz
MIT — siehe 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
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 privacy_guard_scanner-0.2.0.tar.gz.
File metadata
- Download URL: privacy_guard_scanner-0.2.0.tar.gz
- Upload date:
- Size: 27.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1cec02b246b76b5db8fdfe4cff394e2a3c3ab7d5e1dfac5290daea66f87dc8b7
|
|
| MD5 |
b5bcb3120372542c6446dfa043281d35
|
|
| BLAKE2b-256 |
cbb7d4eab02f028fd768da603270d51f1fe73d14921abd3b6e347a02accce796
|
Provenance
The following attestation bundles were made for privacy_guard_scanner-0.2.0.tar.gz:
Publisher:
release.yml on adrian-lorenz/privacy-guard
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
privacy_guard_scanner-0.2.0.tar.gz -
Subject digest:
1cec02b246b76b5db8fdfe4cff394e2a3c3ab7d5e1dfac5290daea66f87dc8b7 - Sigstore transparency entry: 991602672
- Sigstore integration time:
-
Permalink:
adrian-lorenz/privacy-guard@d325529b3362f32070d7b6087f9c1f79ea1bc3da -
Branch / Tag:
refs/heads/main - Owner: https://github.com/adrian-lorenz
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@d325529b3362f32070d7b6087f9c1f79ea1bc3da -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file privacy_guard_scanner-0.2.0-py3-none-any.whl.
File metadata
- Download URL: privacy_guard_scanner-0.2.0-py3-none-any.whl
- Upload date:
- Size: 31.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e2ac2280a1b3645da907de6797cd5c22e797c45a424fdfbb7eb01ae33234a209
|
|
| MD5 |
06e76334d6d456d9e0c5c05a93507cbf
|
|
| BLAKE2b-256 |
5518def2b05c100ee6874c0ad0f21c007afe483822b79383665f9d7107b4ac19
|
Provenance
The following attestation bundles were made for privacy_guard_scanner-0.2.0-py3-none-any.whl:
Publisher:
release.yml on adrian-lorenz/privacy-guard
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
privacy_guard_scanner-0.2.0-py3-none-any.whl -
Subject digest:
e2ac2280a1b3645da907de6797cd5c22e797c45a424fdfbb7eb01ae33234a209 - Sigstore transparency entry: 991602675
- Sigstore integration time:
-
Permalink:
adrian-lorenz/privacy-guard@d325529b3362f32070d7b6087f9c1f79ea1bc3da -
Branch / Tag:
refs/heads/main - Owner: https://github.com/adrian-lorenz
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@d325529b3362f32070d7b6087f9c1f79ea1bc3da -
Trigger Event:
workflow_dispatch
-
Statement type: