Engineering

How we build legal AI

Most of legal AI does not show its work. These are the internals of ours: what our citation verifier actually checks, how retrieval survives a pin cite to a subsection, how we write native Word tracked changes, and the infrastructure underneath. Written by the people who ship it, and specific enough to argue with.

We Made Our Database Deliberately Lose All Its Data

Why we run a production database UNLOGGED on purpose: for a derived, reproducible dataset, durability is a cost, not a virtue, and the recovery path is the refresh path.

Priyansh Khodiyar · 12 min readRead

Cutting a BM25 Index Build From Four Hours to Ninety Minutes

How we cut a BM25 index build from four hours to ninety minutes: index build time scales with the bytes of text you hand the tokenizer, not the row count.

Priyansh Khodiyar · 14 min readRead

Who in Legal AI Actually Shows Their Work?

Who in legal AI actually publishes real engineering content? A survey of the sector's transparency, and why showing your work is a costly signal a small team can send.

Priyansh Khodiyar · 12 min readRead

How We Think About Hallucination in Legal AI

A seven-type taxonomy of legal AI hallucination mapped to a four-layer defense: retrieval grounding, prevention, detection, and honest uncertainty.

Priyansh Khodiyar · 16 min readRead

How to Write Real Word Tracked Changes in Python

How to emit native Word tracked changes (w:ins and w:del) from Python with lxml, including the delText gotcha that silently breaks Reject.

Priyansh Khodiyar · 15 min readRead

The Deterministic Layer Under the LLM

Where we deliberately do not use a model: deterministic, testable backstops at the boundaries where correctness is non-negotiable.

Priyansh Khodiyar · 12 min readRead

How We Keep a Legal-AI Product From Regressing

Layered evaluation for a legal AI product: a deterministic routing sweep plus a live end-to-end harness, diffed before every rollout.

Priyansh Khodiyar · 14 min readRead

We Ran 1,341 Prompts Through Our Router to Find Out What Misroutes

We ran 1,341 prompts through our router and published the results, including the severe false-whole-doc misroute metric.

Priyansh Khodiyar · 18 min readRead

How to Verify an AI's Citations in Code, Not With Another Model

Deterministic citation verification in code: range-check, substring-verify, drop-and-downgrade, then a gated model call.

Priyansh Khodiyar · 14 min readRead

One Retriever Is Not Enough

Multi-query, corrective RAG, self-RAG, multi-hop, and HyDE as our code actually runs them, including which ones fire by default.

Priyansh Khodiyar · 14 min readRead

Research a Hard Question the Way a Lawyer Would: In Pieces, Then Synthesized

Decompose a multi-issue legal question into dimensions, research each in parallel, and render a cited Word memo verbatim.

Priyansh Khodiyar · 13 min readRead

Knowing When You Do Not Know

Multi-sample consistency, sentence-level groundedness, and calibration that discounts overconfidence: how a legal AI knows when it does not know.

Priyansh Khodiyar · 12 min readRead

Teaching the Reviewer How Your Firm Negotiates

The playbook data model behind an AI reviewer: standard position, fallback ladder, deal-breaker floor, and a deterministic structure linter.

Priyansh Khodiyar · 14 min readRead

Draft the Fix, But Earn It

An agentic per-clause repair loop that plans, diagnoses, drafts, validates, and critiques, and knows when to abstain.

Priyansh Khodiyar · 14 min readRead

Call US Law From Your Own Code: The Statutes and Regulations API

Call US law from your own code: the statutes and regulations API over USC, CFR, state codes, and court rules, with official-source links.

Priyansh Khodiyar · 10 min readRead

A Spreadsheet Where Every Cell Is a Cited, Verified Extraction

A document matrix where every cell is a cited, verified extraction: per-cell retrieval, a strict two-outcome schema, and literal-substring verification.

Priyansh Khodiyar · 13 min readRead

The Tracked Changes a Document Is Hiding

Deterministic OOXML detection of the tracked changes, moves, and hidden text a document is hiding behind its rendered view.

Priyansh Khodiyar · 11 min readRead

Real Word Redlines, Not a Diff View

Native OOXML tracked changes a lawyer can Accept or Reject in Word, plus the grounding and sign-off gates behind them.

Priyansh Khodiyar · 11 min readRead

The Law Is Not Clean Data

Defensive modeling for messy US statutes: alphanumeric title numbers, an amendment-year sanitizer, and the guards that keep dirty data honest.

Priyansh Khodiyar · 13 min readRead

Extract Once, Read Many: The Shared Evidence Spine Behind a Matter Workspace

One extraction spine behind Facts and Summary: extract once, read many, and stay consistent by construction rather than by reconciliation.

Priyansh Khodiyar · 12 min readRead

Sending 'Rewrite This Transcript, NOT a Summary' to the Right Engine

Why an LLM classifier alone misroutes 'rewrite this, NOT a summary', and how deterministic regex guards backstop it.

Priyansh Khodiyar · 14 min readRead

Catching a Fabricated [N] Before It Reaches the Lawyer

A deterministic, zero-false-positive gate that strips fabricated citation markers before they reach the lawyer, distinct from after-the-fact verification.

Priyansh Khodiyar · 11 min readRead

What Our Citation Verifier Actually Checks

What a legal AI citation verifier actually checks: a two-phase verifier, why the denominator matters, and six prompts to test any vendor's verifier.

Priyansh Khodiyar · 15 min readRead

Hybrid Retrieval for Law, and the Citation-to-a-Subsection Problem

Why semantic search is blind to exact identifiers like a pin cite to a subsection, and how dense plus BM25 plus reranking fixes it.

Priyansh Khodiyar · 11 min readRead

Review contracts, draft policies, and ship faster, with cited authority.

Every answer shows its source. Your data stays yours, we never train on it. 7-day free trial.