Context
The challenge
Public housing authorities operate under complex, frequently updated federal and local policy documents. Staff must answer resident and internal questions quickly and accurately, but policy manuals are lengthy, versioned, and difficult to search manually. Traditional document tools lack AI-assisted retrieval, and generic chatbots cannot provide cited, auditable answers tied to specific policy versions—a critical requirement for compliance. Existing solutions often bundle RAG and tenancy into a monolith, making it hard to change AI workflows, enforce per-tenant limits, or produce tamper-evident audit records. PHAs need a platform that ingests and versions policy documents securely, lets staff query policy in natural language with source citations, records every interaction in an immutable compliance ledger, and scales across multiple housing authorities without data leakage.
How we worked
Our approach
PHIL uses a separation-of-concerns architecture: a FastAPI backend as the compliance control plane (multi-tenancy, auth, limits, S3 storage, audit ledger, webhooks), n8n for orchestration of ingestion and assistant pipelines, LightRAG for per-tenant knowledge-graph and vector retrieval, and AWS (ECS, ECR, S3, PostgreSQL) for production infrastructure. The backend never runs LLM/RAG logic directly—it dispatches work to n8n via authenticated webhooks and validates responses before writing immutable audit records, so AI workflows can evolve without redeploying the API.
Delivery
The solution
Staff upload policy PDFs/DOCX with version metadata; the API stores files in AES256-encrypted S3, dispatches to n8n with a presigned URL and tenant namespace, and n8n indexes into LightRAG then callbacks with HMAC-signed status (pending → processing → complete | failed). Queries check plan limits, resolve active documents for policy_as_of, create a pending audit record, dispatch to the n8n assistant webhook, validate citation excerpts, and seal a completed HMAC-integrity audit row. Features include HITL acknowledgment, tiered usage plans (standard/pro/enterprise/unlimited), four-tier auth (admin secret, tenant API key, staff user key, internal n8n secret), stuck-ingestion sweepers, integrity verification, and compliance PDF export via ReportLab. Built on Python 3.12, FastAPI, SQLAlchemy 2 async, Alembic, PostgreSQL immutability triggers, and GitHub Actions CI/CD to ECS.
Results
Key metrics
- Per-authority LightRAG namespaces
- Tenant Isolation
- Immutable + HMAC-sealed
- Audit Ledger
- 4-tier (admin/API/staff/n8n)
- Auth Models
- n8n + LightRAG control plane
- AI Pipeline
Impact
Results & outcomes
- Faster natural-language policy lookup for staff instead of manually searching hundreds of pages
- Compliance-ready immutable audit trail with HMAC integrity hash, staff attribution, policy scope, and structured citations
- Multi-tenant SaaS with isolated LightRAG namespaces, per-tenant API keys, and timezone-aware usage limits
- Policy version accuracy via policy_as_of historical queries when regulations change
- Cost control through document caps, daily query limits, and monthly token budgets with clear 429/reset_at responses
- Tamper-evident operations via HMAC-signed keys and callbacks plus PostgreSQL triggers blocking audit mutation
- Flexible AI pipeline—RAG/LLM logic lives in n8n + LightRAG without backend redeploys for prompt or model changes
- Production-grade AWS ECS deployment with health/readiness checks, CI/CD, and operational safeguards
Tech used
Technology stack
Tools and patterns from this engagement—your stack may differ.