Stack: Python • Flask • SQLAlchemy • Postgres (or SQLite) • LangChain • OpenAI (or other LLM)
Features: schema-aware LLM→SQL translation (with conservative fallback), RBAC & PII masking, audit logging, per-user privacy budgets, Laplace & Gaussian differential privacy for aggregates.
- copy
.env.example→.envand edit if needed - (Optional) create a Postgres DB and set
DATABASE_URLin.env - install:
python -m venv venv source venv/bin/activate pip install -r requirements.txt - init DB & seed:
python3 init_db.py
- run:
python3 app.py
How it works
-
LLM→SQL: uses LangChain's SQLDatabaseChain if OPENAI_API_KEY is set; otherwise falls back to a conservative rule-based translator that only supports basic patterns.
-
RBAC & PII masking: policies determine which columns each role can access and whether PII values (ssn/name) are masked.
-
Differential privacy: aggregates use Laplace (ε-DP) or Gaussian (ε,δ-DP) mechanisms. Gaussian sigma computed with sigma >= sqrt(2 ln(1.25/delta)) * sensitivity / epsilon.
-
Privacy budgets: each user has an epsilon budget tracked in DB. Aggregate queries deduct the requested epsilon.