Design a Citation-Verified RAG Assistant for Litigation Review
Machine LearningModel answerLast updated
Design a read-only, retrieval-grounded LLM system that summarizes case files, builds timelines, flags conflicting statements, and drafts briefs with verifiable citations and strong isolation.
Problem
A law-firm platform wants an AI assistant for attorneys preparing contested cases. Each case ("matter") holds a large pile of discovery material: pleadings, contracts, email threads, scanned exhibits, and deposition transcripts. The assistant should help the team build factual timelines, find places where witnesses or documents disagree, answer questions, and draft preparation briefs. It is a drafting aid only: it must not give legal advice, take outside actions, or state anything it cannot trace to a source.
Requirements
Functional
- Ingest mixed formats (scanned PDFs with OCR, email threads, transcripts), each tied to exactly one matter.
- Every factual sentence in an output must cite its exact source: page, paragraph, Bates number, or transcript page and line.
- Detect and surface conflicting statements about the same event or claim across witnesses and documents.
- Operate read-only with attorney review and approval before any draft is final. Refuse legal advice.
Non-functional and security
- Documents may contain adversarial text that tries to hijack the model (indirect prompt injection). The design must neutralize it.
- Immutable audit logs of queries and responses, per-matter encryption keys, and retention or deletion rules including litigation holds.
- Citation precision above 99%. Hallucinated facts are unacceptable.
Scale
- A typical matter has about 50,000 documents (~250,000 pages); the largest reach 1,000,000 documents.
- 50 concurrent matters, peak 100 queries per second.
- Ingestion of 10,000 pages in under 30 minutes.
- Interactive Q&A must reach first token in under 4 seconds; long drafts stream.
What to cover
- End-to-end architecture: parsing, structure-aware chunking with Bates and speaker metadata, hybrid (dense + lexical) retrieval, and synthesis.
- How the model is constrained to produce verifiable claims, and how citations map back to text spans or page regions.
- How you detect contradictions across documents and witnesses.
- Security: separating instructions from untrusted content, matter isolation, injection defenses.
- An evaluation plan covering retrieval recall, faithfulness, citation precision, and advice refusal.
Hints
Hint 1
Treat the LLM as an untrusted component: never let it write citations itself. Have it reference opaque chunk handles plus verbatim quotes, and compute the human-readable citation from stored metadata.
Hint 2
Comparing every pair of passages for contradictions is quadratic and noisy. Extract structured event claims first, then group candidates by resolved entity and time window before running an NLI-style classifier.
Hint 3
For injection, combine layers: sanitize hidden text at ingestion, screen retrieved chunks, fence evidence as data in the prompt, and remove tools entirely so a successful injection has nothing to act on.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
What a strong answer looks like
This is RAG with a higher bar: deterministic provenance, hostile inputs, and strict isolation. The core stance is that the LLM is untrusted. Its inputs are sanitized and fenced, and its outputs are verified against source text before anyone sees them.
1. Sizing
- Corpus: 250K pages typical; a 1M-document matter may reach several million pages. At ~3 chunks per page, that is ~15M chunks. At 1024-dim fp16 (~2 KB each), roughly 30 GB of vectors per large matter and low single-digit TB across 50 matters.
- Ingestion: 10K pages per 30 minutes is ~5.6 pages/s. Provision ~3x headroom (~20 pages/s). OCR and layout at 1-2 pages/s per GPU worker means a pool of 10-20 workers, autoscaled from a queue.
- Latency budget (4 s to first token): retrieval ~300 ms, rerank ~300 ms, injection screen ~200 ms, prefill ~1.5 s, remainder as buffer. Long drafts stream and verify per sentence.
2. Data model
Each chunk stores its anchor in data, not in model memory: matter_id, doc_id, bates_begin/end, page, paragraph, doc_type, deponent, transcript page and line range, email message/thread IDs and headers, text, bounding boxes, content hash, injection_score, privilege_flag.
For contradictions, extract event tuples: (subject, action, object, normalized_time, location, polarity, modality, asserted_by, chunk_id).
3. Architecture
Ingestion
- Files land in a matter-scoped bucket encrypted with a per-matter KMS key; hash and dedupe.
- Parse by type: OCR plus layout for scans, a page:line parser for transcripts, MIME/thread parsing for email (strip quoted history).
- Chunk by structure: Q/A exchange for depositions, clause for contracts, message body for email. Attach Bates and line metadata.
- Sanitize: remove hidden text (white-on-white, tiny fonts, off-page), normalize Unicode, drop zero-width characters, score each chunk with an injection classifier.
- Index into per-matter namespaces: dense vectors and BM25 (lexical search matters for names, Bates numbers, defined terms). Event extraction runs asynchronously.
Query path
- A small model with no document access rewrites and decomposes the question.
- Hybrid retrieval (top ~200 from each), reciprocal rank fusion, cross-encoder rerank to ~20.
- Injection screen on retrieved chunks; flagged ones are shown to the user as flagged but never inserted into the prompt.
- Prompt assembly: system instructions, then evidence in clearly delimited envelopes with opaque IDs (
C17). - Constrained generation of structured claims:
{claim_text, chunk_id, quote_span}. - Verification and rendering (below), then an immutable audit write.
4. Grounding and provenance
The model never writes a Bates number. A post-processor checks each claim:
- Existence: the chunk ID must be in this request's retrieved set.
- Quote match: the quote must appear in the chunk (exact or fuzzy, e.g. normalized edit distance under 2%). Matched offsets map to bounding boxes or transcript lines, producing citations like
Smith Dep. 45:12-46:3with click-through highlighting. - Entailment: an NLI or judge model confirms the quote supports the claim, catching "real quote, wrong conclusion."
- Coverage: every factual sentence needs a verified citation; only headings are exempt.
Failures are dropped or labeled "unsupported." The system abstains ("no supporting passage found") instead of guessing. Citation precision above 99% is reachable because targets are computed, and the residual error (misattribution) is gated by conservative entailment thresholds.
A policy classifier blocks advice-like output ("you should settle", "liability is clear"). No tools are exposed, so there are no external actions.
5. Contradiction analysis
- Extract event tuples per chunk, normalizing times (resolve relative references via the chronology, keep a confidence).
- Block candidates: cluster tuples sharing resolved entities and an overlapping time window or event cluster, so comparisons happen inside small groups.
- Classify pairs as consistent, contradictory, or unrelated with a fine-tuned NLI cross-encoder, escalating high-value pairs to an LLM adjudicator. Add typed checks: temporal (different dates for one event), polarity ("never saw the memo" vs. a document showing receipt), and quantity or identity mismatches.
- Present both sides with citations, confidence, and a note on hedged language ("I believe") that weakens a conflict. The attorney decides what matters.
Trade-off: higher recall means more false positives and reviewer fatigue. Rank by confidence and materiality, and tune for recall on high-stakes issues.
6. Security
- Instruction/data separation: documents are only ever in evidence envelopes; the system prompt states that envelope content is data, never instructions. Structured output limits what an injected instruction can change.
- Layered injection defense: ingestion sanitization, classifier scoring, query-time screening, quarantine, and output validation. Because the system is read-only with no tools, the blast radius is a bad draft, which verification and review catch.
- Isolation: per-matter indexes, per-matter keys, ACL and ethical-wall checks on every call, and the matter filter enforced in the retrieval layer, not just the prompt. Never share caches across matters.
- Audit and retention: append-only (WORM) logs of query, retrieved IDs, outputs, and reviewer actions. Litigation holds block deletion; on release, crypto-shredding the matter key enforces hard deletion.
7. Evaluation
- Retrieval: recall@k and MRR on attorney-labeled question-to-passage sets, per document type.
- Faithfulness: claim-level entailment rate against cited spans, using human-audited samples to calibrate the judge.
- Citation precision/recall: fraction of citations whose span supports the claim; fraction of factual sentences cited. Gate releases on precision above 99%.
- Contradiction quality: precision/recall on seeded and annotated conflicts.
- Safety: red-team suites with injected documents (hidden text, role-play payloads) measuring attack success; advice-refusal rate on adversarial prompts.
- Operations: p95 time to first token, ingestion throughput, reviewer edit rate.
Common mistakes
- Letting the model generate citations or Bates numbers.
- Dense-only retrieval, which misses exact names and IDs.
- Filtering by matter in the prompt instead of in the index.
- Pairwise comparison of all passages for contradictions.
- Relying on a single injection classifier instead of defense in depth.
- Skipping abstention, which pushes the system toward confident hallucination.