Enterprise RAG: Automating Legal Contract Audits
Built a private, single-tenant LLM pipeline with hybrid vector search (Weaviate + Pgvector) to process, index, and semantically summarize 10,000+ legal contracts with 99% accuracy.
The Challenge
A multinational law firm managing 10,000+ active contracts across 14 jurisdictions needed to audit every agreement for non-standard indemnification clauses, change-of-control provisions, and GDPR data processing addenda. Their paralegals were spending 40+ hours per contract on manual review, and the backlog was growing faster than the team could process it.
Existing keyword search tools missed semantically equivalent clauses — for example, a clause stating "upon acquisition of a controlling interest" would not match a search for "change of control." The firm needed semantic understanding, not string matching.
Our Approach
We built a Retrieval-Augmented Generation (RAG) pipeline running entirely within the firm's private cloud to satisfy attorney-client privilege requirements. No data leaves the tenant boundary.
Document Ingestion: Contracts in PDF, DOCX, and scanned formats are processed through a pipeline combining Apache Tika for text extraction, Tesseract OCR for scanned documents, and a custom layout parser that preserves clause numbering and section hierarchy.
Hybrid Vector Search: Each clause is embedded using a fine-tuned legal domain embedding model (based on E5-large) and stored in both Weaviate (for semantic search) and Pgvector (for metadata-filtered retrieval). This dual-index approach allows queries like "find all indemnification clauses in contracts governed by German law signed after 2022."
LLM Analysis: Retrieved clauses are passed to a GPT-4-class model with structured output prompting. The model classifies each clause against a taxonomy of 47 clause types, extracts key terms (cap amounts, time limits, governing law), and flags deviations from the firm's standard playbook.
Human-in-the-Loop: Every LLM output is presented to a reviewing attorney in a custom interface that shows the source clause highlighted in the original document alongside the model's classification and extracted terms. Attorneys can accept, reject, or modify each extraction, and corrections feed back into the fine-tuning pipeline.
Results
| Metric | Before | After |
|---|---|---|
| Review time per contract | 40+ hours | 8 hours |
| Clause extraction accuracy | Manual baseline | 99% |
| Backlog processing rate | 12 contracts/month | 60 contracts/month |
| Missed non-standard clauses | ~15% estimated | < 1% |