Back to Blog
Published:
Last Updated:
Recently Updated
Legal Contract ReviewChapter 2

Smart Category Routing for Contract Review

6 min read
1,300 words
medium priority
Mudassir Marwat

Mudassir Marwat

Founder & CEO, Cognilium AI

Smart Category Routing for Contract Review — Cognilium AI

TL;DR

A focused application of the LLMOps routing pattern to legal contract analysis — the analyst-selection logic that ships fewer clauses to fewer agents and finishes a 3,300-call review in 154 seconds.

Contract review is a domain where the LLMOps routing pattern earns its complexity. A typical contract has 50-100 chunks. Each chunk is potentially relevant to one or two of 11 specialist analysts (compliance, indemnity, IP, payment, termination, etc.). Running every analyst on every chunk is 1,100+ LLM calls. Routing cuts that to ~250.

Playbook-driven configuration

Each customer has a playbook in S3 — categories that matter to them, severity weights, and party-specific clauses (one customer cares deeply about IP indemnity; another cares about data-residency clauses). At job start, the system loads the playbook and configures analysts accordingly.

  • Categories: 12 standard, 1-3 customer-specific
  • Severity weights: how much to escalate findings in each category
  • Party-specific clauses: customer-defined patterns the analyst should specifically look for

Per-chunk scoring

Each chunk runs through 12 category scorers (cheap model, $0.25/M tokens). Each scorer emits a 0-100 score for "is this chunk relevant to my category?" The router selects analysts to run based on the scores: above-threshold categories trigger their analyst; below-threshold categories skip.

HyDE-augmented retrieval

HyDE runs at ingestion, per playbook term. The enrichment agent generates a hypothetical ideal answer for each term — search-optimized text embedded alongside the term itself — so retrieval matches contract chunks against what a relevant clause would say, not against the term's literal wording. Better recall than embedding the label alone, especially when the playbook uses legal jargon and the contract uses plain English (or vice versa).

LLM reranking after HyDE

Vector search returns the top ten candidate chunks per playbook term; an LLM reranker scores each candidate and narrows to the three most relevant, which are deduplicated before anything reaches an analyst. The wide first pass is allowed to be cheap and loose because the reranker pays the precision bill.

Numbers from production

  • 22 chunks → 116 LLM calls per chunk (12 scorers + ~3 routed analysts × ~30 LLM calls each) = ~660 calls per chunk on the misleading top-line
  • Actually: 22 chunks × 12 scorers + ~3 selected analysts per chunk × 8 calls = 264 + 528 = ~800 calls per contract typical
  • P50 review time: 154 seconds end-to-end
  • Per-contract cost: $0.50-2.00 depending on contract length and customer playbook
  • Reduction vs. naive fan-out: ~75%

Where this fails

Customer playbooks with overlapping categories (the "compliance" category overlaps with "regulatory" and "data-handling" 70% of the time). Routing collapses to "everyone." Mitigation: routing analytics dashboard shows per-category overlap rates; surfaces the problem; encourages playbook tightening.

Share this article

The work behind this series

The review pipeline these articles describe — extraction, category routing, parallel scoring and human escalation — as an engagement.

Mudassir Marwat

Mudassir Marwat

Founder & CEO, Cognilium AI

Mudassir Marwat's argument is that ERP systems record decisions they never optimise.

Founder & CEO of Cognilium AI; 37 AI agents in production across four products; 4 production AI products built and operated; three clouds in production (AWSGCPAzure)
Agentic AIRAG → GraphRAG retrievalVoice AIMulti-Agent Orchestration
In short

Key takeaways

  • Score cheaply, analyze expensively: a cheap scoring pass across every category decides which specialist analysts a chunk deserves, so the expensive models run only where routing says they will pay.
  • The playbook is customer configuration, not code — categories, severity weights and party-specific clauses steer routing without a redeploy.
  • Retrieval is enriched at ingestion: each playbook term carries hypothetical-answer text, so matching works even when the contract and the playbook use different vocabulary.
  • A wide, cheap retrieval pass followed by an LLM reranker keeps recall high and analyst context tight — the reranker, not the vector search, sets precision.
What goes wrong

Common mistakes to avoid

  • Fanning every chunk out to every analyst because routing looks like premature optimization — the routing layer is where most of the cost reduction lives.
  • Designing playbook categories that overlap, which routes the same clause to multiple specialists and produces duplicate findings.
  • Embedding the playbook term's literal wording and blaming the model for missed matches — the vocabulary gap between legalese and plain English is a retrieval problem, not a model problem.

Frequently Asked Questions

Find answers to common questions about the topics covered in this article.

Same routing pattern, applied to contract analysis specifically. This chapter walks the legal-domain choices: how categories are defined, how the playbook is loaded per job, how HyDE-augmented retrieval seeds the per-chunk context.
Hypothetical Document Embeddings: generate a pretend "ideal answer" to the query, embed that, retrieve similar real chunks. Often retrieves better than embedding the literal query — particularly when query language differs from corpus language.
Per-job ephemeral storage. Each contract review creates a fresh ChromaDB instance with that job's chunks; tear down at job end. No tenant cross-contamination, no long-running index to maintain. Pinecone would work; the cost-per-job is lower with ephemeral Chroma.
Each customer has a playbook in S3 (categories, severity weights, party-specific clauses). At job start, the playbook loads into the analyst configuration. Different customers analyze the same contract differently — playbook-driven configuration handles that.
When the playbook is poorly defined (categories overlap, severity weights are uniform), routing collapses to "everyone." Encourages teams to invest in playbook precision; provides routing analytics to show where overlaps cause routing failures.

Still have questions?

Get in touch with our team for personalized assistance.

Contact Us

Still have a question this did not answer?

The person who wrote this article answers these. Describe your setup and what you are stuck on — you will get a straight answer, including where we think the approach is wrong.

Related Articles

Continue exploring related topics and insights from our content library.

The Production LLMOps Stack: Evals, Judges, Retries, Circuit Breakers
11 min
1
Mudassir Marwat
May 5, 2026

The Production LLMOps Stack: Evals, Judges, Retries, Circuit Breakers

The day-2 ops layer of an LLM product — what to evaluate, what to judge in real time, what to retry, and when to fail closed. The components that turn a prototype into something operable.

words
Read Article
LLM-as-Judge With Temperature-Escalation Retry Inside a 60-Second Budget
7 min
2
Mudassir Marwat
May 5, 2026

LLM-as-Judge With Temperature-Escalation Retry Inside a 60-Second Budget

Judge scores below 85? Retry with temperature 0.3, 0.4, 0.5 — three attempts inside a 60-second wall-clock budget. The simple loop that hits 99.5% on-spec output without crossing the latency ceiling.

words
Read Article
Smart Category-Score Routing That Cuts LLM Cost ~75%
7 min
3
Mudassir Marwat
May 5, 2026

Smart Category-Score Routing That Cuts LLM Cost ~75%

A pipeline of 12 scorers + 11 analysts does not need to fan out everywhere. Route each chunk to matching analysts and save three quarters of the LLM bill.

words
Read Article

Explore More Insights

Discover more expert articles on AI, engineering, and technology trends.

Personalized for You

Curated content recommendations based on your current reading and interests.

For You
82%

Can you change an agent's prompt without a redeploy?

Same topic cluster: Legal Contract Review
Matches your interests

Hot-reloading agent prompts and thresholds from a parameter store is operationally excellent and a governance problem — a behaviour change with no diff, no review and no rollback story.

Ali Ahmed
6 min read
Legal Contract Review
Read Article
Trending
67%

What a Dynamics 365 F&O database refresh does not copy, and what breaks after it

Same author: Mudassir Marwat
Preferred author

A refresh copies production into a sandbox, then disables every user, withholds every batch job, clears every secret and drops every endpoint. The checklist.

Mudassir Marwat
5 min read
D365 Platform Decisions
Read Article
For You
82%

What stops a degraded model from taking the whole queue with it?

Same topic cluster: Legal Contract Review
Matches your interests

Retry is how a degraded model provider becomes an outage. A circuit breaker fails fast instead — and in a container fleet it protects far less than you think, because every replica has its own.

Ali Ahmed
6 min read
Legal Contract Review
Read Article
For You
82%

Deterministic parsing or a model — when is the cheapest call the one you never make?

Same topic cluster: Legal Contract Review
Matches your interests

The same pipeline ingests a spreadsheet with no model calls and a PDF with dozens. The format your customer sends decides your unit economics — which makes the upload form a cost lever most teams never touch.

Ali Ahmed
7 min read
Legal Contract Review
Read Article
For You
82%

Your container is mid-message and autoscaling just killed it

Same topic cluster: Legal Contract Review
Matches your interests

Amazon ECS documents task scale-in protection and names queue-processing workloads in its first example. It works — and it will block your next deployment in ways AWS spells out and most teams discover during a release.

Ali Ahmed
7 min read
Legal Contract Review
Read Article
For You
82%

How do you review a contract against your own legal playbook with AI?

Same topic cluster: Legal Contract Review
Matches your interests

A contract review system that reads your own playbook is four services and three queues. This is the whole pipeline — what each stage costs, where it degrades, and the one design decision the architecture is built around.

Ali Ahmed
8 min read
Legal Contract Review
Read Article

Smart Recommendations

Our AI analyzes topic clusters, author expertise, and content relationships to surface the most relevant articles for you.

Topic Matching
Author Expertise
Content Quality
Personal Interests

Questions on this?

Talk to an engineer

Schedule a call