How-toby Ahsan Ahmad

RAG for law firms: searching contracts and case files without hallucinations

Summary

Law firms can use retrieval-augmented generation (RAG) to search contracts, precedents and case files in plain language, with every answer quoting and linking the exact passage it came from. To avoid hallucinations, answer only from retrieved passages, say so when nothing is found, split contracts at clause boundaries, use hybrid search for defined terms and case names, and test on fee earners' real questions. Enforce matter-level access and ethical walls before retrieval, keep documents in the firm's own accounts, and start with search-shaped tasks like clause finding and precedent search. Leave questions of law and client-facing output to lawyers.

What can RAG do for a law firm?

Retrieval-augmented generation (RAG) lets lawyers ask questions in plain language across a firm's own documents - contracts, precedents, case files, internal know-how - and get an answer that quotes and links the exact passages it relied on. It is search that reads, not a system that gives legal advice. The lawyer still decides what the passages mean.

The most useful early applications are narrow: finding every contract in a data room with a change-of-control clause, pulling the firm's preferred wording for an indemnity, locating where in a long bundle a witness said something, or answering "have we handled this before?" across past matters.

Why are hallucinations a bigger problem for law firms than for other businesses?

Because a fluent wrong answer in legal work can be relied on, filed or sent to a client. A general chatbot that invents a clause or a citation is embarrassing elsewhere; in a law firm it can be a professional-conduct problem. That shifts the design goal: the system should be built so that every statement can be checked against a source in one click, and so that "I could not find this" is a normal, frequent answer.

The techniques that make that possible are not exotic. What matters is that they are all present, and tested on the firm's own documents.

How do you build legal document search that doesn't hallucinate?

Answer only from retrieved passages, and show them

Every answer is built from passages retrieved from the firm's documents, and every claim links to the passage, document and page it came from. If nothing relevant is retrieved, the system says so rather than answering from the model's general knowledge.

Respect document structure

Contracts have clauses, schedules and definitions that change the meaning of everything else. Splitting documents at clause boundaries and keeping defined terms attached to the passages that use them avoids a whole class of wrong answers that come from reading half a clause.

Search exact words as well as meaning

Lawyers search for defined terms, case names, statute sections and party names, where an exact match matters. Hybrid search - keyword matching alongside semantic search, with a re-ranker - finds these where meaning-only search returns something merely related. Our vector database notes cover the options.

Handle versions and scans

Drafts, executed versions and amendments of the same agreement must be distinguishable, and older bundles are often scanned. Version metadata and proper text recognition for scanned pages are part of the build, not extras.

Test on the firm's own questions

A set of real questions from fee earners, with the correct passages identified by a lawyer, is the only meaningful measure of accuracy. Our post on QA for RAG systems explains how that testing differs from testing ordinary software.

How do you protect client confidentiality in a law firm RAG system?

The same way the firm protects it everywhere else: by making sure people can only see what they are entitled to see, and by knowing exactly where the data goes. This is a design requirement from the first day, not a feature added at the end.

  • Access control per matter, mirrored from the firm's document management system, applied before retrieval - so a lawyer never receives a passage from a matter they are walled off from, even in a summary.
  • Ethical walls and conflict restrictions enforced in the retrieval layer, not left to the prompt.
  • Model providers and hosting chosen to meet the firm's data terms, with documents and prompts not used for training, and data kept in the regions the firm requires.
  • Full logs of who asked what and which documents were returned, retained under the firm's policies.
  • Documents stay in the firm's own cloud accounts, with keys in the firm's name.

Professional-conduct and data-protection obligations differ by jurisdiction, and the firm's own risk and compliance team should sign off the design. Our security and data handling page sets out how we handle client data, and EU AI Act compliance covers the transparency duties for EU deployments.

Which legal tasks suit RAG first, and which don't?

Legal tasks and how well they suit retrieval-augmented generation
TaskFitWhy
Finding clauses across a set of contractsStrongAnswer is a passage that exists; easy to verify
Precedent and know-how searchStrongReplaces manual hunting through past matters
Locating facts in a large case bundleStrongCitations point to page and line
First-pass summaries of a document for the lawyerGood, with reviewUseful, but every point needs a source
Comparing a draft against the firm's standard termsGood, with reviewHighlights differences; a lawyer judges them
Answering questions of lawPoorNeeds judgement and authority beyond the firm's documents
Anything sent to a client without reviewNot suitableThe lawyer remains responsible for the advice

Should a law firm buy a legal AI product or build its own RAG system?

Many firms should start with a legal AI product. Several are built specifically for law firms, come with legal research content and integrations into common document management systems, and have already been through other firms' security reviews.

A custom system makes sense when the value is in the firm's own documents and know-how rather than public legal content, when the firm uses a document management system or matter structure a product does not support, when data must stay in the firm's own cloud under its own keys, or when per-seat pricing across every fee earner costs more over a few years than owning the system.

From us, document search over one corpus with citations and an admin interface is a fixed $5,500-9,000 build over five to seven weeks. Multi-tenant search with isolation and single sign-on - the shape that matter-level access control usually needs - is $12,000-20,000 over eight to twelve weeks. See RAG development for what is included.

How should a law firm pilot a RAG system?

  1. 01

    Pick one practice group and one corpus

    A closed set - one practice group's precedents, or one transaction's data room - with an enthusiastic partner sponsoring it.

  2. 02

    Collect real questions with known answers

    Forty questions fee earners have actually asked, with the correct passages identified by a lawyer. This is the acceptance test.

  3. 03

    Agree the threshold before building

    How often must the right passage appear, and how often may it answer without one? Agree it before anyone sees results.

  4. 04

    Measure time saved, not impressions

    Compare how long the same searches take with and without the system. That is the number the partners will ask for.

Can law firms use RAG without hallucinations?

Yes, if the system answers only from retrieved passages, links every claim to its source and says when it cannot find something - and if it is tested on the firm's own questions. Apply matter-level access control before retrieval, keep documents in the firm's own accounts, and start with search-shaped tasks like clause finding and precedent search, where the answer is a passage a lawyer can check. Leave questions of law and anything client-facing to lawyers.

The general method is in how to implement retrieval augmented generation, and the warning signs of a system going wrong in 7 signs your RAG chatbot is giving wrong answers.

Tell us what you are building

A free strategy session: what is buildable, what it costs, what we would not attempt.

Book a call

Pick a time for a strategy call

It goes straight into our calendar, with no form to fill in first.