Raadhesh/GDPR-Data-Privacy-Sanitizer
๐ก๏ธ GDPR Data Privacy Sanitizer
An RL environment where an AI agent must mask Personally Identifiable Information (PII) in a relational SQLite database โ without breaking foreign-key integrity or distorting statistical distributions.
๐ Real-World Value
GDPR, CCPA, and HIPAA regulations require organisations to protect personal data. Manual compliance is slow, error-prone, and does not scale.
This environment teaches RL agents to automate privacy-preserving data transformations โ a problem worth billions of dollars in compliance costs every year.
The agent must learn:
๐ Architecture
โโโโโโโโโโโโโโโโโโ JSON Action โโโโโโโโโโโโโโโโโโโโ
โ LLM Agent โ โโโโโโโโโโโโโโโโโโโโโโโโถ โ DataPrivacyEnv โ
โ (Llama 3 / โ โ (SQLite DB) โ
โ Groq API) โ โโโโโโโโโโโโโโโโโโโโโโโโ โ โ
โโโโโโโโโโโโโโโโโโ Observation + Reward โโโโโโโโโโโโโโโโโโโโObservation Space
Action Space
Reward Structure
๐ฏ Tasks
Easy โ Column Redaction
Redact email and phone in the Users table. Grading: 1.0 if both columns contain only [REDACTED]. Partial credit (0.5) for one column.
Medium โ Referential Hashing
Hash Users.id and Purchases.user_id with SHA-256. A JOIN between the tables must still return all 5 original rows. Grading: 1.0 if hashes are consistent and the JOIN succeeds. 0.0 otherwise.
Hard โ Statistical Jittering
Jitter Employees.salary so that every value changes, but AVG(salary) remains within 5% of the original. Grading: 1.0 if all salaries changed and the average is within tolerance. 0.0 otherwise.
๐ Quick Start
1. Install Dependencies
pip install -r requirements.txt2. Set Your API Key
We use Groq for free Meta Llama 3 inference (you can also use any OpenAI-compatible endpoint):
export GROQ_API_KEY="gsk_your_key_here"3. Run the Inference Script
# Easy task (default)
python inference.py
# Medium task
TASK=medium python inference.py
# Hard task
TASK=hard python inference.py4. Run the Server (for judge validation)
uvicorn server:app --host 0.0.0.0 --port 7860Then test:
curl -X POST http://localhost:7860/reset5. Docker
docker build -t gdpr-sanitizer .
docker run -p 7860:7860 gdpr-sanitizerโ Validation
The judges' validate-submission.sh checks:
- Dockerfile exists โ
- Container builds โ
- `POST /reset` returns 200 OK โ
This submission passes all three checks.
๐ Project Structure
.
โโโ models.py # Pydantic Observation & Action schemas
โโโ db_utils.py # SQLite database setup with mock data
โโโ environment.py # Core OpenEnv environment (step/reset/state)
โโโ graders.py # Programmatic graders (easy/medium/hard)
โโโ server.py # FastAPI HTTP wrapper (/reset, /step, /state)
โโโ inference.py # Async LLM agent with strict logging
โโโ openenv.yaml # OpenEnv configuration
โโโ Dockerfile # Container (python:3.10-slim, port 7860)
โโโ requirements.txt # Python dependencies
โโโ README.md # This file๐งช Technical Notes
- LLM Backend: Uses the
openaiPython client pointed at Groq's free API (https://api.groq.com/openai/v1) withllama3-8b-8192. Swap by settingAPI_BASE_URLandMODEL_NAMEenvironment variables. - Structured Output: The LLM is prompted to return raw JSON matching the Pydantic
Actionschema.response_format={"type": "json_object"}enforces valid JSON. - Dense Rewards: Every step provides immediate feedback, enabling faster RL convergence.
- Safety: Destructive SQL keywords (
DROP,DELETE, etc.) are detected and immediately terminate the episode with a โ1.0 penalty.
๐ License
MIT โ Built for the Meta PyTorch ร Hugging Face OpenEnv Hackathon.
