Skip to main content
Glama

ClauseIQ

A multi-agent AI system that reads an Indian contract, flags the clauses that are unfair to you with a severity score, and cites the exact section of Indian law behind each one.

Runs as a streaming web app and as an MCP server inside Claude Desktop.

▶ Live app · Install into Claude Desktop (MCP)


The problem

People in India sign rental, employment, and freelance contracts every day with clauses that are quietly unfair — or unenforceable under Indian law, and have no way to tell which. A 12-month lock-in that forfeits your entire deposit. A two-year, all-India non-compete. "Raise any dispute within 7 days or lose it forever." Lawyers are expensive; generic AI chatbots hallucinate sections of law that don't exist.

ClauseIQ is the tool I wanted to exist: it reads the contract, flags the risky clauses with a 1–5 severity score, explains why in plain language, and — the part that matters — backs every flag with a real, verified citation to the Indian Contract Act, 1872.

Related MCP server: Consulente Legale

Live demo

Add a GIF/screenshots here: docs/assets/demo.gif, docs/assets/analysis.png.

  • Web app: https://clauseiq-app-fawn.vercel.app — paste a contract or upload a PDF and watch the agents work live.

  • API: https://clauseiq-api-124621416027.asia-south1.run.app (Cloud Run; GET /health for liveness, /docs for the OpenAPI UI).

  • In Claude Desktop (MCP): ask "analyse this contract for unfair clauses" — see docs/MCP_INSTALL.md.

System architecture

One application core, exposed through two front doors (a REST/streaming API and an MCP server). The analysis itself is a LangGraph state machine of four agents:

flowchart LR
    subgraph Clients
      Web[React app<br/>SSE streaming]
      Claude[Claude Desktop<br/>MCP]
    end
    Web -->|POST /analyze/stream| API[FastAPI]
    Claude -->|stdio| MCP[MCP server]
    API --> Core
    MCP --> Core
    subgraph Core[Application core - LangGraph]
      direction LR
      S[Supervisor<br/>segment + screen] --> R[Retriever<br/>hybrid search] --> RA[Risk Analyzer<br/>score 1-5] --> CV[Citation Verifier<br/>drop hallucinations]
    end
    R -.-> VS[(ChromaDB + BM25<br/>Indian Contract Act)]
    S & RA -.-> G[Gemini 2.5<br/>flash + pro]
    Core --> OBS[Langfuse + cost tracking]

Hybrid retrieval fuses dense vectors (ChromaDB) and lexical BM25 via Reciprocal Rank Fusion. The Citation Verifier is the anti-hallucination guarantee: any cited section that isn't in the corpus is dropped before you ever see it.

Key design decisions

  1. One core, two front doors (dual-mode MCP). The agents live in the application layer with zero knowledge of transport; FastAPI and the MCP server are thin adapters over the same ContractAnalyzer. Tradeoff: a strict hexagonal boundary is more upfront structure, but it's why the exact same analysis runs in a browser and inside Claude Desktop with no duplicated logic.

  2. Gemini via Vertex AI, with automatic fallback to AI Studio. Orchestration on gemini-2.5-flash, analysis on gemini-2.5-pro. In production it runs on Vertex AI (billed to GCP credits, authenticated by the Cloud Run service account — no key on the server); if Vertex is unavailable or the credits run out, the client automatically falls back to an AI Studio key, so the app keeps working. Tradeoff: a single-vendor (Google) dependency, in exchange for ~zero cost, strong structured output, and resilience — and Claude is still free via the user's own Claude Desktop over MCP.

  3. A deterministic citation metric, not just LLM judges. Citation accuracy is checked against the actual statute (existence + text overlap), so the anti-hallucination guarantee never depends on another model's opinion. Tradeoff: it only catches citation faults, so it's paired with LLM-judged faithfulness for the rest.

  4. Eval-gated CI. A 20-case golden dataset runs in CI; the build fails if faithfulness or citation accuracy regress. Tradeoff: slower, token-spending CI, but prompt regressions can't silently ship.

  5. Result types + guardrails over exceptions for expected failures. Expected failures (not-a-contract, prompt injection, missing law) are typed Result values and explicit guardrails, not stack traces. Tradeoff: more verbose call sites, far more predictable behaviour at the API/MCP boundary.

Evaluation results

Measured with DeepEval over the full 20-case golden dataset (5 each: rental, employment, NDA, vendor). LLM-judged metrics use Gemini as judge; Citation Accuracy is deterministic (checked against the statute).

Metric

Score

Gate

Type

Citation Accuracy

1.00

≥ 0.90 ✅

deterministic

Faithfulness

0.90

≥ 0.85 ✅

LLM judge

Answer Relevancy

0.90

informational

LLM judge

Legal Soundness (G-Eval)

0.82

informational

LLM judge

Contextual Precision

0.57

informational

LLM judge

Contextual Recall

0.26

informational †

LLM judge

CI gates on Citation Accuracy + Faithfulness — the deterministic anti-hallucination guarantee plus grounding. The rest are reported for insight.

† Contextual Recall compares the gold summary against the raw statute snippets cited, which structurally understates it (the summary states legal conclusions not verbatim in the statute) — it's not a retrieval failure, as the perfect Citation Accuracy and 0.90 Faithfulness show.

Scores are produced by tests/evaluation/ and gated in CI.

Cost per query

Per analysis (segmentation on gemini-2.5-flash + per-clause analysis on gemini-2.5-pro), tracked live via a per-model price table and surfaced in logs, the SSE done event, and Langfuse.

Measured across the 20-case eval run (avg; range $0.0034–$0.0190 by contract size).

Component

Model

~Cost / contract

Segmentation / orchestration

gemini-2.5-flash

~$0.0008

Clause analysis

gemini-2.5-pro

~$0.0063

Retrieval + citation verify

local / deterministic

$0

Embeddings

all-MiniLM-L6-v2 (local)

$0

Total per contract

~$0.007

What I'd do differently

  • Hosted vector DB + per-tenant isolation. Embedded ChromaDB is perfect for a single-instance demo; a real product needs a managed store and isolation.

  • Expand the law corpus. Today it's the Indian Contract Act, 1872; rent-control and labour statutes are stubbed. State-specific coverage is the obvious next step.

  • Severity-calibration metric. The eval checks faithfulness and citations; I'd add a per-clause severity-MAE metric against expert labels.

  • Adversarial golden cases. Add benign/near-miss contracts to measure the false-positive rate, not just recall on unfair clauses.

Tech stack

Backend

Frontend

Python 3.11, FastAPI

React 18, Vite, TypeScript (strict)

LangGraph (multi-agent)

Tailwind v4, shadcn/ui

ChromaDB + rank-bm25 (RRF)

TanStack Query, Zustand

sentence-transformers (MiniLM)

Zod (runtime validation)

Google Gemini 2.5 (flash + pro)

Framer Motion (streaming UI)

MCP (FastMCP, stdio)

Biome, Vitest

DeepEval, Langfuse, structlog

pnpm

uv, ruff, mypy --strict, pytest

Lighthouse 100/98/100/91

Quickstart

# Backend (terminal 1)
uv sync
echo "CLAUSEIQ_GEMINI_API_KEY=your_key" > .env
uv run python scripts/ingest_laws.py          # build the vector index (once)
uv run uvicorn clauseiq.interfaces.api.main:app --app-dir src --reload --port 8000

# Frontend (terminal 2)
cd frontend && pnpm install && pnpm dev        # http://localhost:5173

API docs at http://localhost:8000/docs. Run the test suite with uv run pytest.

Deployed on Google Cloud Run (backend) and Vercel (frontend), with Gemini on Vertex AI.

Install into Claude Desktop (MCP)

ClauseIQ runs as an MCP server, so you can analyse contracts and look up Indian law directly inside Claude Desktop. Setup takes under a minute — see docs/MCP_INSTALL.md.


Disclaimer: ClauseIQ is automated decision-support, not legal advice. Amendment history is not tracked; verify current law for time-sensitive matters.

Available Tools

3 tools
analyze_contractA

Analyse an Indian contract: flag unfair clauses with a 1-5 severity, a rationale, and citations to the exact sections of Indian law that back each flag.

Args:
    contract_text: The full text of the contract to analyse.
ParametersJSON Schema
NameRequiredDescriptionDefault
contract_textYes

Output Schema

ParametersJSON Schema
NameRequiredDescription

No output parameters

TDQS

A4/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It explains the tool's output format (severity, rationale, citations) and that it analyzes contract text. However, it does not disclose potential side effects, required permissions, or whether the operation is read-only. The description is adequate but lacks rich behavioral context.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single sentence with a clear purpose, followed by an explicit Args section. It is front-loaded, uses no unnecessary words, and every part contributes useful information. It is concise and well-structured.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of contract analysis with legal citations, the description adequately explains what the tool does and what outputs to expect. The presence of an output schema likely details the return structure further. Sibling tools provide additional context, and the description is complete for an agent to understand the tool's functionality.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 0% description coverage, but the description's Args section fully explains the sole parameter 'contract_text' as 'The full text of the contract to analyse.' This adds complete semantic meaning beyond the bare schema, fully compensating for the lack of schema descriptions.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool analyzes an Indian contract, specifically flagging unfair clauses with severity ratings, rationales, and citations to Indian law. This is a specific verb-resource combination that distinguishes it from sibling tools like search_indian_law and verify_citation.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description does not provide any explicit guidance on when to use this tool versus alternatives. There is no mention of prerequisites, limitations, or scenarios where another tool would be more appropriate, such as searching for specific laws or verifying citations.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

search_indian_lawA

Search the Indian Contract Act, 1872 for sections relevant to a query.

Args:
    query: A legal topic or question (e.g. "agreement in restraint of trade").
    k: Number of sections to return (default 5).
ParametersJSON Schema
NameRequiredDescriptionDefault
kNo
queryYes

Output Schema

ParametersJSON Schema
NameRequiredDescription

No output parameters

TDQS

A3.8/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden. It states it searches a specific act and returns sections but fails to disclose whether it is read-only, how results are ordered, or any additional behavioral traits (e.g., pagination, rate limits). The description is minimal.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is short and front-loaded with purpose. The Args block is a bit formal but adds structure. Every sentence contributes meaning, though the Args format could be more concise.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given there is an output schema (not shown) but no annotations, the description explains input well but omits output format or behavior (e.g., does it return relevance scores? How many sections typically?). For a search tool, this is a noticeable gap, but output schema may cover returns.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, but the description adds meaningful explanations: query is described as 'A legal topic or question' with an example, and k as 'Number of sections to return (default 5).' This provides value beyond the schema's bare type and default.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description explicitly states 'Search the Indian Contract Act, 1872 for sections relevant to a query.' This is a specific verb ('search'), a clear resource (the Act), and distinct purpose. It differentiates from siblings: 'analyze_contract' suggests analysis, 'verify_citation' suggests checking references.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description includes an example query ('agreement in restraint of trade') and a default value for k, offering practical usage context. However, it does not explicitly state when to use this tool versus alternatives like 'analyze_contract' or 'verify_citation', nor does it provide exclusions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

verify_citationA

Verify that a cited section of Indian law actually exists in the corpus.

Args:
    claim: The legal claim the citation is meant to support.
    citation: The citation to check, e.g. "ICA_1872:27" or "Section 27".
ParametersJSON Schema
NameRequiredDescriptionDefault
claimYes
citationYes

Output Schema

ParametersJSON Schema
NameRequiredDescription

No output parameters

TDQS

A3.6/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It only states that the tool verifies existence but does not disclose what happens if the citation is invalid (e.g., returns false/error), the expected response format, or any security/privacy considerations. This is minimal for a simple verification tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is highly concise: one sentence for purpose and a structured list for arguments. No wasted words, and the structure is clear with 'Args:' section.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

The tool is simple (2 parameters), and an output schema exists (as per context). The description covers the core action and parameter examples but omits details on return values or behavior on failure. However, with an output schema, the return format is likely documented elsewhere. A note on what 'verify' entails beyond existence would improve completeness.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 0% description coverage, but the description includes an 'Args' section providing brief explanations with examples ('e.g. "ICA_1872:27" or "Section 27"'). This adds moderate meaning beyond the schema, but does not fully compensate for the lack of detail in the schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: verifying that a cited section of Indian law exists in the corpus. It uses a specific verb ('verify') and resource ('cited section'), distinguishing it from siblings like search_indian_law (which searches broadly) and analyze_contract (which analyzes contracts).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage when a citation needs verification, but it does not explicitly state when to use this tool instead of alternatives like search_indian_law or analyze_contract. There is no exclusion or guidance on when not to use it.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

  1. 3 tool updatesv0.1.0
    • First observedanalyze_contract
    • First observedsearch_indian_law
    • First observedverify_citation

TDQS

A4/5.0

Scored across 3 tools

Disambiguation5/5

Each tool has a distinct purpose: analyzing contracts, searching Indian law, and verifying citations. No overlap in functionality, making it easy for an agent to select the correct tool.

Naming Consistency5/5

All tool names follow a consistent verb_noun pattern (analyze_contract, search_indian_law, verify_citation), with lowercase and underscores. No mixing of conventions.

Tool Count5/5

With 3 tools, the set is well-scoped for a specialized legal assistant focused on Indian contract analysis. Each tool earns its place without being too few or excessive.

Completeness4/5

The tools cover the main workflow: analyze a contract, search relevant law, and verify citations. A minor gap is the lack of a tool to retrieve the full text of a specific section by ID, but the search tool likely fulfills that need.

Maintenance

ActivityMaintained
ResponsivenessNo issues

Related MCP Connectors

Related MCP Servers

  • F
    license
    Not graded
    quality
    C
    maintenance
    A Model Context Protocol server that enables Claude (or any MCP client) to read and write Clio Manage data—contacts, matters, activities—directly from chat, with flat-fee billing support in one call.
    -
  • A
    license
    A
    quality
    B
    maintenance
    MCP server that gives Claude safety-gated access to SpotDraft contracts, enabling querying and managing contracts, templates, counterparties, obligations, and analytics through natural language.
    19
    MIT