The problem
Law firms working on consumer-credit and similar matters receive thick case files: scans, annexes, letters. Sorting them, finding key facts and spotting abusive clauses is hours of reading, and a number from an AI that nobody can check is worthless to a lawyer.
What I built
A pipeline: ingest (page split, sha256 deduplication) → extract → anonymize → classify → facts → clauses. A Postgres job queue with retries and visible failures keeps it running. OCR escalates per page: text layer first, then local Tesseract, and only a page the quality detectors reject goes to a cloud vision model — not the whole file.
Quality detectors guard the output: ink coverage catches hallucinated text, character density catches lost content, compression catches a model stuck in a loop, number matching catches an invented figure. Facts are normalised by a local verifier (amounts incl. spelled-out ones, dates, percentages) and located on the page. Abusive-clause findings must cite an entry from the UOKiK register or a statute article; a finding without one is not created.
Personal data is masked before any model sees it: PESEL and NIP with checksum validation plus NER, property-tested. Un-anonymised text cannot reach an LLM by construction, enforced by a test. Tenants are isolated with Postgres row-level security and every action lands in an append-only audit log. The model runs in the EU (AWS Bedrock Frankfurt, Gemini) with zero retention and a data-processing agreement. A lawyer reviews and decides.
Stack
Python · FastAPI · PostgreSQL · pgvector · AWS Bedrock · Gemini · Tesseract · Docker · React · Vite · pytest