← Back to HAQQ Blog

Legal Ontology AI: How We Cut Legal AI Costs by 97%

By Stephane Boghossian · · 25 min read · Ai-legal-tech

A legal ontology replaced 300 MCP tools with 7, dropping AI costs from $0.60 to $0.02 per message. Stanford proved RAG hallucination rates of 17-33%. Here's the architecture, the 7-step playbook, and why we're building this for UAE labor law.

How a Demo Call Rewrote My Roadmap

A few weeks ago, I got on a call with the CEO of Dynamic Interfaces to look at something they built — a legal ontology system for Mexican labor law. I figured I'd see a demo, take some notes, move on. That's not what happened.

I've been building legal AI at HAQQ for the MENA region, and I've sat through enough 'revolutionary' demos to last a lifetime. Most of them are just RAG with a nicer UI. This system looked different from the first five minutes. Not because of slick design or marketing speak — because of what was happening under the hood.

Here's the thing that stopped me cold: 5 Mexican government customers were using this system daily. Court-appointed expert witnesses — peritos — were querying labor law across four federal statutes, getting precise answers with full legal citations, and the whole thing cost two cents per message. Not two dollars. Two cents.

For context, Harvey AI — the $11B golden child of legal AI — charges $1,200 per lawyer per month. CoCounsel starts at $220/month. Even the cheapest seat in legal AI runs $100+/month. And here was this system in Mexico doing it for two cents per message. No subscriptions. No seat minimums. Just a structured knowledge graph and 7 well-designed tools.

I spent the next two weeks pulling the system apart to understand why it works. This article is what I found, why it matters for anyone building legal AI, and what we're building at HAQQ because of it.

What the $11B Legal AI Companies Get Wrong

Before I get into the ontology architecture, I need to say something blunt about the current state of legal AI. Because the more I dug into the competitive landscape, the more a pattern emerged — and it's not flattering for the incumbents.

Every major legal AI company is a RAG wrapper. Not one has a formal legal ontology.

Harvey AI — $11B valuation, $1.2B raised, backed by Sequoia and GIC — runs fine-tuned LLMs with RAG over legal databases. They charge ~$1,200/lawyer/month at list price. They just announced a LexisNexis integration, adding another $400-600/lawyer/year. They claim 91% accuracy on their 'BigLaw Bench.' That still means 9% of legal work contains errors.

CoCounsel (Thomson Reuters) — 1 million users, bolted onto Westlaw's 100+ years of case law. Multi-model architecture across Anthropic, OpenAI, and Google. Pricing from $220 to $500/user/month. Better data moat than Harvey. But still RAG at its core.

Legora (formerly Leya) — $5.55B valuation, 800 law firms. Built on Claude with agentic workflows. $250/user/month, 10-seat minimum. No proprietary legal knowledge structure. It's a very well-designed wrapper.

Stanford ran a preregistered empirical study — the first of its kind. Magesh et al., published in the Journal of Empirical Legal Studies in 2025. They tested production legal RAG tools and found hallucination rates of 17-33% across the board.

Meanwhile, in clinical medicine, researchers published a paper showing that ontology-grounded GraphRAG hit 98% accuracy versus ChatGPT-4's 37%. That's not a typo. A 61-percentage-point improvement, published in the Journal of Biomedical Informatics, using SNOMED CT as the grounding layer.

The medical domain proved it. The legal domain needs it. And nobody's building it. That's the gap. That's what HAQQ is walking into.

The Experiment: Poking Around Inside a Legal Ontology via MCP

I want to be upfront about what this was. Not a product review. Not a partnership announcement. This was me connecting to Dynamic Interfaces' MCP server, exploring their ontology data structures, analyzing the design, and stress-testing it against everything I know about legal reasoning.

The Model Context Protocol (MCP) — Anthropic's standard for AI-tool integration, now governed by the Linux Foundation — was the interface. Every action in the ontology is exposed as a callable MCP tool. Any MCP-compatible client can plug in.

Ontologies are kind of the secret.

A 2025 paper on tool selection found that reducing tool count tripled accuracy — from 13.6% to 43.1% — while cutting prompt tokens by over 50%. Fewer tools, dramatically better performance. That's exactly what the ontology does: collapses hundreds of granular database operations into a handful of semantically meaningful legal operations.

Why Does Legal AI Fail? The 3 Fatal Flaws of RAG for Law

Most legal AI products — including most of what exists in the MENA market — are doing RAG over PDFs. They chunk legal documents, embed them in a vector database, and retrieve semantically similar passages when you ask a question. This works for general knowledge queries. It fails catastrophically for law.

At least 6 attorneys have been sanctioned for filing AI-generated fake case citations since 2023 — starting with the now-infamous Mata v. Avianca case where ChatGPT fabricated cases and then confirmed they 'indeed exist' in Westlaw.

Temporal Blindness

RAG systems can't inherently distinguish between the 2022 version and the 2023 version of a legal article. Mexico's 2023 'Vacaciones Dignas' reform doubled vacation entitlements overnight. A perito calculating a wrongful dismissal case spanning that boundary needs both versions. RAG has no mechanism for this. None.

Structural Ignorance

Law is hierarchically structured: Constitution, Federal Law, Regulations, Circulars. Within a law: Titles, Chapters, Articles, Fractions, Paragraphs. RAG chunking destroys this hierarchy. When Article 50 says 'in the terms of Article 48,' a RAG system may retrieve Article 50 without Article 48, producing an incomplete answer.

Cross-Reference Amnesia

Legal reasoning is inherently graph-based. A seniority premium calculation under Article 162 references UMA values defined in the Constitution. INFONAVIT housing credits are calculated in UMAs per a 2016 reform. A RAG system has no mechanism to follow these reference chains. It retrieves fragments. An ontology traverses connections.

A legal knowledge graph is a network of legal provisions connected by typed, semantic relationships. Unlike a document index where connections are inferred by keyword similarity, a legal knowledge graph explicitly encodes that Article 50 'establishes a formula' referenced by Article 48, which in turn 'refers to' Article 84's salary definition.

What Is a Legal Ontology and How Does It Work?

A legal ontology is a structured, machine-readable knowledge model that represents a legal domain as a graph of entities (laws, articles, courts, computed values), their hierarchical relationships, and typed cross-references between provisions. Unlike flat-text retrieval systems, a legal ontology preserves the inherent structure of legislation — hierarchy, versioning, exceptions, and formula chains — enabling deterministic legal reasoning rather than probabilistic document retrieval.

Scale: 11 entity types, 1,689 articles, 4 federal laws, 7 judicial precedents, 12 typed cross-references, 10 enum taxonomies.

How Typed Cross-References Change Legal AI Reasoning

What makes this ontology architecturally powerful is the typed cross-reference system. In most legal AI systems, a reference between two articles is just a hyperlink. In Dynamic Interfaces' system, it's a typed relationship with semantic meaning: remite_a (refers to), complementa (complements), modifica (modifies), excepciona (creates exception), define_termino (defines term), establece_formula (establishes formula), establece_procedimiento (establishes procedure).

That excepciona type — that's the one that keeps me up at night. Article 5 of the LFT establishes general labor rights, but special work regimes create exceptions. If your system doesn't model exceptions explicitly, it applies general rules where special rules should apply. That's a legally catastrophic mistake.

How Much Does a Legal Ontology Reduce AI Costs?

This is where it goes from 'architecturally interesting' to 'holy shit, this changes the business model.' A legal ontology reduced AI reasoning costs from $0.60 to $0.02 per message — a 97% reduction — by collapsing 300 MCP tool descriptions into 7 ontology-aware tools.

Why Do Ontology-Based Legal AI Systems Need Fewer Tools?

Token Economics: Why 300 Tools Cost $0.60 and 7 Tools Cost $0.02

The standard approach to building AI agents is to expose every database operation as a separate tool. Multiply that across 11 entity types and you hit 300 tools fast. Here's the problem: every one of those tool descriptions gets serialized into the LLM's context window on every single request. With 300 tools at roughly 300 tokens each, you're burning 90,000 tokens before the user even asks a question.

The ontology collapses this. Instead of 300 granular database operations, you get 7 semantically meaningful legal operations: query_legal_knowledge, calculate_settlement, find_jurisprudencia, get_cross_references, get_wage_data, get_vacation_table, generate_dictamen.

Seven tools. 2,100 tokens for descriptions. $0.02 per message.

The Model Downgrade Effect: From Frontier to Open-Source

When an AI agent only has 7 well-defined tools to choose from — instead of 300 — the model doesn't need to be as smart. The ontology does the heavy structural lifting. The model just needs to understand the user's question, pick the right 1-3 tools, and synthesize a response from structured data.

The Perito Salary Math

A perito laboral in Mexico City earns roughly 15,000-30,000 MXN per month. At $0.60 per message, with 50 cases per month and 20 messages per case, the API cost alone would be $600/month — 36-72% of their income. Completely non-viable.

At $0.02 per message, the same usage costs $20/month — 1.2-2.4% of income. Less than a Netflix subscription. The cost reduction doesn't just make the product cheaper. It makes an entirely new market possible.

Deep Dive: A Real Wrongful Dismissal Calculation — $254,000 MXN

This is a complete wrongful dismissal calculation using actual LFT articles, real 2026 wage data, and the full cross-law dependency chain. Maria Elena Gutierrez, administrative assistant, monthly salary $15,000 MXN, employed 5 years 3 months, terminated without just cause.

The ontology handles it in 8 steps across 4 laws: classify the dispute, check binding precedent, follow the formula chain, compute indemnification ($1211,000), settlement ($5,000), back wages ($120,000), cross-law verification, for a grand total of $254,000 MXN.

The UMA Trap: A $180,000 Mistake Hiding in Plain Sight

Since Mexico's 2016 constitutional reform, two reference units coexist: the UMA (Unidad de Medida y Actualizacion) and the Salario Minimo (minimum wage). In 2026, the minimum wage is 2.69 times the UMA. Using the wrong one doesn't produce a rounding error. It produces a legally invalid calculation.

If you calculate the prima de antiguedad cap using UMA instead of Salario Minimo, you get $234.62/day instead of $630.08/day — shortchanging the worker by 62.8%. An ontology encodes which reference unit applies to which legal concept. It's not ambiguous. A RAG system leaves it to the LLM to figure out. That's where the hallucination lives.

Can a Legal Ontology Work for Any Jurisdiction?

Every legal system shares five structural primitives: hierarchical legislation, semantic categorization, cross-reference graphs, temporal versioning, and computed domain values — making the ontology pattern universally replicable. The pattern is universal. The enums are jurisdiction-specific.

The pattern maps most cleanly onto civil law systems — France, Brazil, Saudi Arabia, UAE — because they share codified, hierarchical structures nearly identical to Mexican law. Common law systems need an adaptation layer that elevates case law to first-class status alongside statutes.

What This Means for HAQQ — and the $1.2B MENA Opportunity

Nobody in MENA is doing this. Not even close. The competitive landscape is dominated by RAG-over-PDFs. Al Tamimi partnered with Harvey. Legora launched Arabic support in January 2026. There are 185+ legal tech companies in the region. But not one has built a structured ontology with typed cross-reference graphs for MENA labor law.

The GCC Legal Technology Market is worth $1.2B. The UAE Legal Tech market is projected to reach $234.4M by 2030 (CAGR 10.8%). The UAE government has allocated $572M for digital transformation across the justice sector. Saudi Arabia's Vision 2030 includes specific legal technology modernization provisions.

The UAE's Federal Decree-Law No. 33 of 2021 is roughly 65 articles plus implementing regulations. Saudi Arabia's labor law is about 245 articles. These are manageable corpora — small enough to build a complete, human-validated ontology in weeks, not months.

Arabic-first is our advantage. Per ArabLegalEval benchmarks, Arabic legal NLP lacks benchmarking frameworks available for English. An ontology sidesteps NLP extraction entirely — it provides structured data. The LLM does synthesis, not extraction. That's a much simpler task.

Machine-Readable Law: We're Not Alone

Singapore announced SOLID (Singapore Open Legal Informatics Database) in November 2025. The EU has been running the European Legislation Identifier (ELI) since 2012, now implemented by 21+ countries. New Zealand's 'Better Rules' initiative develops legislation simultaneously in plain language, rule statements, and code.

The pattern is clear: the governments investing in computational law now will have the infrastructure for legal AI later. The ones that aren't will be buying expensive RAG wrappers from Silicon Valley.

How to Build a Legal Ontology: A 7-Step Playbook

For a focused legal domain like a single country's labor law (65-245 articles), a complete ontology can be built in 4-8 weeks at a parsing cost of $5-20 per law.

What's Next

We're exploring integration with Dynamic Interfaces' platform for ontology definition and SDK generation. We're building a UAE Labor Law Ontology — Federal Decree-Law No. 33 of 2021 is our first target. We're testing with real legal workflows in the UAE, and we plan to open-source the universal entity model.

The insight is almost embarrassingly simple: model law as what it actually is. A structured, versioned, cross-referenced knowledge system. Stop treating it like a pile of PDFs to search through.

Every major legal AI company is built on RAG. Stanford proved they hallucinate 17-33% of the time. Meanwhile, ontology-grounded systems hit 98% accuracy. The architecture exists. The academic validation exists. The market exists. The ontology is the secret. We're building ours.

Questions I Keep Getting

What is a legal ontology, exactly?

A legal ontology is a structured, machine-readable model of a legal domain. Think of it as a knowledge graph specifically designed for law — it defines entities, maps hierarchical relationships, tracks typed cross-references, and handles temporal versioning for reforms. Instead of treating law as flat text to search through, a legal ontology captures the actual structure that legislation already has.

How is ontology-based legal AI different from RAG?

RAG chunks legal documents and retrieves semantically similar passages. An ontology models law as a connected knowledge graph with typed relationships. In practice, this means RAG loses hierarchy, temporal versioning, and cross-reference chains. An ontology preserves all three. The result is deterministic legal reasoning instead of probabilistic retrieval — the difference between 'probably right' and 'cite-ably right.'

How does this compare to Harvey AI?

Harvey is a $11B company charging ~$1,200/lawyer/month with a 20-seat minimum. They use fine-tuned LLMs with RAG — no formal ontology. They claim 91% accuracy, which still means 9% error rate. The ontology approach costs $0.02/message with deterministic calculations that don't hallucinate numbers. The architectures are fundamentally different: Harvey makes the model smarter; the ontology approach makes the model's job simpler.

How much does it actually save?

Per-message costs dropped from $0.60 to $0.02 — that's 97%. The savings come from collapsing 300 MCP tool descriptions into 7 (saving ~87,900 tokens per request) and enabling the switch from frontier models to open-source ones.

Can this work for common law systems?

Yes, but with an adaptation layer. Civil law systems map directly because they share codified, hierarchical structures. Common law systems need to elevate case law to first-class status alongside statutes. The five structural primitives exist in every legal system.

How long does it take to build one?

For a focused domain like a single country's labor law: 4-8 weeks for a small corpus (65-245 articles). That includes source parsing, entity modeling, cross-reference extraction, and MCP tool generation. Parsing costs run $5-20 per law.

References