Source-grounded legal review
Summary
Contract analysis inside the client’s infrastructure.
Lawyers needed to find clauses, compare terms and inspect potential risks across heterogeneous legal documents.
A pipeline for OCR, document structure, clause retrieval and risk extraction, with source references and exportable review results.
Tech Stack
- Python
- PostgreSQL
- Redis
- OCR
- SpaCy
- Milvus
- Sentence Transformers
- Retrieval-Augmented Generation (RAG)
- Prompt Engineering
Tech Challenge
- Scalable Ingestion Pipeline. M&A data rooms contain hundreds to thousands of documents in varied formats. We needed a robust pipeline to handle OCR, metadata extraction, and content normalization quickly.
- Clause-Level Understanding. The assistant must identify key legal clauses, extract obligations, and detect crucial risks or anomalies in documents.
- Cited, contextual answers. The system was designed to ground findings in retrieved legal text and expose source references for review.
- Custom Legal Taxonomies and Schema. NDAs, MSAs, board resolutions, and commercial leases all carry different review requirements. The system needed flexible, domain-aware tagging and search across contract types.
- Enterprise-Grade Security and Deployment. Legal documents contain confidential and privileged information. Our platform had to support full encryption, fine-grained access controls, audit logging, and VPC or on-prem deployment options.
Solution
- Documents are uploaded or synced via secure integrations. We use OCR, PDF parsers, and layout-aware NLP to extract structural metadata (dates, parties, signatures, etc.).
- Clause-level embeddings are stored in Milvus, allowing the LLM to retrieve highly relevant passages for analysis and summarization.
- A custom RAG layer ensures summaries and Q&A responses are grounded in retrieved text. Prompts are domain-tuned for legal accuracy.
- Multilayer LLM-based architecture identifies and categorizes key clauses (e.g., indemnity, termination, governing law) and detects possible risks.
- AI Assistant is equipped with tools for exploring summaries, clicking on citations, tagging documents, and exporting structured reports.
- The solution is deployed within the client’s infrastructure without external model APIs, keeping document processing within the agreed deployment boundary.
- The system operates without reliance on external APIs or third-party platforms, providing full data sovereignty and making it easier to meet strict regulatory, privacy, and client confidentiality requirements.
Impact
Outcome
A pilot that connects legal-review findings with the underlying contract clauses.
The pilot combined document ingestion, clause retrieval and source-linked findings. Lawyers remained responsible for interpreting the material.
Published
