Back to Work
production

Government Legal Document RAG

Government Institution (via Apiux Tech)2025

A production retrieval-augmented generation system over 1M+ legal documents, enabling structured drafting of legal petitions and tutela responses with full audit trails and human-review controls.

1M+
Legal Documents
50→90%
Drafting Accuracy
60%
Review Time Saved

Context

The institution needed to accelerate the drafting of legal petitions and tutela responses across an archive of over 1M legal documents. Manual drafting was slow, inconsistent across drafters, and difficult to audit — a significant constraint for a government body operating under legal and compliance scrutiny.

Problem

Two requirements had to be met simultaneously: accurate retrieval over a large, heterogeneous legal corpus, and drafting output that matched the institution’s formal legal writing conventions. Because outputs carry legal weight, every step also needed a full audit trail and a human-review gate before anything left the system.

Architecture

The system combines supervised fine-tuning (SFT) on the institution’s drafting patterns with retrieval-augmented generation over the document archive. vLLM serves the model on-premises to satisfy data sovereignty requirements. A LangGraph-orchestrated pipeline structures the workflow into retrieval, drafting, and review-flagging stages, with PostgreSQL holding document metadata and the audit trail.

Technical decisions

  • On-prem deployment via vLLM, driven by data sovereignty constraints inherent to government data.
  • SFT combined with RAG rather than pure retrieval-augmented generation — pure RAG did not reliably match the institution’s formal drafting style, so the model was fine-tuned on drafting patterns while RAG kept content grounded in the actual archive.
  • Human-in-the-loop review gates at every drafting stage, given the compliance and liability weight of legal outputs.

Evaluation

Drafting accuracy was tracked through a structured human-review pipeline, comparing system-assisted drafts against the unassisted manual-drafting baseline.

Results

  • Drafting accuracy improved from roughly 50% to 90% under human review.
  • Review time reduced by approximately 60%.
  • Retrieval and drafting operate across a 1M+ document archive with full audit trails.
  • vLLM
  • RAG
  • SFT
  • On-Prem Deployment
  • Python
  • LangGraph
  • PostgreSQL