Skip to content

AI / LegalTech

Contract analysis with a multi-agent RAG pipeline

Turns 500 to 1,000 page legal contracts into a queryable knowledge base that answers with cited sources.

The project's architecture, drawn from the stack we used.
Client
Client name withheld
Our role
Designed and built by the CodeBaxh team.
Services
AI IntegrationRAG & Knowledge AssistantsAI Agents & AutomationLLM Evaluation & Guardrails
Stack
PythonFastAPIOpenAIGeminiQdrant

The problem

Reviewing a long legal contract takes hours or days. Generic language models make things up when asked about legal text.

The system had to give accurate answers that trace back to the actual contract language, across documents of 500 to 1,000 pages with complex clauses, tables and cross-references.

Our approach

We built an ingestion pipeline that parses and repairs complex document structure, so the models read clauses, tables and references correctly.

Retrieval runs over a Qdrant vector database with query expansion and multi-step search. The work is split across agents for document processing, retrieval, query understanding and response generation, using OpenAI and Google Gemini models.

The solution

A FastAPI platform where legal teams upload large contracts and ask questions in plain language.

Each answer is generated from the retrieved contract sections, not from the model's memory, and points back to the source clauses.

What we built

  • Document structure repair

    Parses and repairs complex layouts so clauses, tables and references are interpreted correctly.

  • Advanced retrieval

    Query expansion and multi-step search find the right clauses in very long documents.

  • Multi-agent workflow

    Separate agents handle processing, retrieval, query understanding and response generation.

  • Cited answers

    Every response references the source clauses it was built from.

  • Qdrant vector search

    Semantic similarity search across large document sets.

  • FastAPI backend

    OpenAI and Gemini models sit behind a Python API that handles upload and querying.

Results

  • Handles contracts of 500 to 1,000 pages with complex formatting.
  • Answers are grounded in retrieved text and cite the source clauses.
  • Static PDFs became a knowledge base that legal teams can query in plain language.

More work

More AI case studies.

Planning something similar?

Share a short brief and we will reply with next steps, usually within one working day.