A FastAPI-based service for detecting and masking Personally Identifiable Information (PII) in text using the PII-Ranha model.
- PII Detection: Check if text contains any PII
- PII Masking: Mask detected PII with either aggregated or detailed redaction
- Health Check: Verify service status
- Token Chunking: Handles long texts by splitting into 256-token chunks
docker run -p 8000:8000 ghcr.io/burgonet-eu/piiserver
% curl -X POST "http://localhost:8000/check-pii" -i \
-H "Content-Type: application/json" \
-d '{"text":"Your text here, my name is Jean-Claude Dusse"}'
HTTP/1.1 400 Bad Request
date: Thu, 16 Jan 2025 11:40:49 GMT
server: uvicorn
content-length: 34
content-type: application/json
{"detail":"PII detected in input"}
% curl -X POST "http://localhost:8000/check-pii" -i \
-H "Content-Type: application/json" \
-d '{"text":"Your text here, Lorem ipsum dolor sit amet, consectetur adipiscing elit"}'
HTTP/1.1 200 OK
date: Thu, 16 Jan 2025 11:40:07 GMT
server: uvicorn
content-length: 43
content-type: application/json
{"status":"OK","message":"No PII detected"}
POST /check-pii
- Request body:
{"text": "your text here"}
- Returns: 200 if no PII detected, 400 if PII detected
POST /mask-pii
- Request body:
{"text": "your text here"}
- Optional query param:
aggregate_redaction=true|false
(default: true) - Returns: Original and masked text
GET /health
- Returns: Service status
- Install dependencies:
pip install fastapi uvicorn transformers torch
- Run the server:
python app.py
- The service will be available at
http://localhost:8000
Check for PII:
curl -X POST "http://localhost:8000/check-pii" -H "Content-Type: application/json" -d '{"text":"Your text here"}'
Mask PII:
curl -X POST "http://localhost:8000/mask-pii" -H "Content-Type: application/json" -d '{"text":"Your text here"}'
The service uses the PII-Ranha model from Hugging Face.
Author: Sébastien Campion
Sébastien Campion - sebastien.campion@foss4.eu
Note: This project is under active development. Please report any issues or feature requests through the issue tracker.
This project is licensed under the GNU Affero General Public License v3.0 - see the LICENSE file for details.