Skip to content
vineeethhPublic

About

Multi-agent case-law analysis with LangGraph supervisor-worker agents, FastAPI, PostgreSQL and Qdrant, with human review for low-confidence output

Topics

Resources

Stars

3 stars

Watchers

1 watching

Forks

Latest commit

Β 

History

3 Commits

Folders and files

Repository files navigation

βš–οΈ Legal.ai

AI-Powered Multi-Agent Case-Law Intelligence & Analysis Platform

Python LangGraph Qdrant PostgreSQL Docker

πŸ† National 2nd Prize Winner β€” Deloitte Hacksplosion 2026 Selected from 22,000+ applicants


πŸš€ Overview

Legal.ai is a multi-agent AI platform for transforming complex legal judgments into structured, traceable, and verifiable case-law intelligence.

The system processes legal PDFs, extracts important case information, analyzes statutory references, retrieves relevant legal knowledge, validates generated results, and produces structured outputs with supporting evidence and confidence signals.

The project is built around a Supervisor-Worker architecture using LangGraph, with dedicated components for document processing, extraction, retrieval, statute verification, validation, and observability.

Core idea: Use AI to accelerate legal document analysis without treating an LLM's output as automatically correct.


πŸ† Achievement

National 2nd Prize β€” Deloitte Hacksplosion 2026

Legal.ai was recognized with the 2nd prize nationally at Deloitte Hacksplosion 2026, competing among 22,000+ applicants.


✨ Key Features

  • πŸ€– Multi-Agent Legal Analysis β€” Coordinates specialized AI components through a LangGraph workflow.
  • πŸ“„ Legal PDF Intelligence β€” Parses and processes lengthy court judgments and legal documents.
  • 🧠 LLM-Powered Information Extraction β€” Extracts structured case information from unstructured legal text.
  • πŸ”Ž Semantic Retrieval β€” Uses embeddings and Qdrant for vector-based retrieval.
  • βš–οΈ Statute Knowledge Base β€” Supports ingestion, lookup, mapping, and verification of statutory information.
  • πŸ›‘οΈ PDF Safety Checks β€” Screens documents before downstream AI processing.
  • βœ… Evidence-Based Validation β€” Separates extraction from validation to reduce unsupported claims.
  • πŸ“Š Confidence Scoring β€” Combines validation signals to assess the reliability of extracted information.
  • πŸ”„ Retry & Validation Workflow β€” Allows questionable outputs to be re-evaluated within the pipeline.
  • πŸ—ƒοΈ Structured Outputs β€” Converts complex judgments into machine-readable legal information.
  • πŸ”­ LLM Observability β€” Integrates Langfuse for tracing and monitoring AI workflows.
  • 🐳 Dockerized Execution β€” Provides a reproducible environment for document processing and ingestion.

πŸ›οΈ System Architecture

Legal.ai follows a Supervisor-Worker orchestration pattern where a central workflow coordinates specialized processing stages.

graph TD
    A[Legal Judgment PDF] --> B[Document Safety Check]
    B --> C[Document Parsing & Chunking]
    C --> D[Supervisor / LangGraph Workflow]

    D --> E[Case Metadata Extraction]
    D --> F[Legal Facts & Issues]
    D --> G[Arguments & Evidence]
    D --> H[Statute Analysis]

    E --> I[(Qdrant Vector DB)]
    F --> I
    G --> I
    H --> I

    E --> J[(PostgreSQL / Supabase)]
    F --> J
    G --> J
    H --> J

    H --> K[Statute Knowledge Base]
    K --> H

    I --> L[Retrieval & Verification]
    J --> L
    L --> M[Validation]
    M --> N[Confidence Scoring]
    N --> O[Structured Legal Report]
Loading

High-Level Flow

Legal PDF
   β”‚
   β–Ό
Safety & Parsing
   β”‚
   β–Ό
Document Chunking
   β”‚
   β–Ό
Supervisor / LangGraph
   β”‚
   β”œβ”€β”€β–Ί Case Metadata
   β”œβ”€β”€β–Ί Facts & Issues
   β”œβ”€β”€β–Ί Arguments & Evidence
   └──► Statute Analysis
              β”‚
              β–Ό
       Retrieval / Knowledge Base
              β”‚
              β–Ό
          Validation
              β”‚
              β–Ό
       Confidence Scoring
              β”‚
              β–Ό
      Structured Legal Output

🧩 Core Engineering Concepts

1. Supervisor-Worker Workflow

Instead of sending an entire judgment to one monolithic prompt, Legal.ai divides the workflow into specialized stages.

                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚    Supervisor   β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                             β”‚
          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
          β–Ό                  β–Ό                  β–Ό
   Metadata Agent      Evidence Agent     Statute Agent
          β”‚                  β”‚                  β”‚
          β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                             β–Ό
                       Validation
                             β”‚
                             β–Ό
                     Final Structured
                          Output

This makes the pipeline easier to extend, test, observe, and validate.


2. Retrieval-Augmented Legal Intelligence

Legal.ai combines LLM reasoning with vector retrieval rather than relying solely on model memory.

Legal Text
    β”‚
    β–Ό
Embeddings
    β”‚
    β–Ό
Qdrant
    β”‚
    β–Ό
Relevant Context
    β”‚
    β–Ό
LLM / Agent
    β”‚
    β–Ό
Validated Result

This architecture helps ground generated information in retrieved document or knowledge-base context.


3. Statute Verification

The dedicated statute_kb/ layer supports legal statute handling through:

  • Act registration
  • Statute ingestion
  • Legal text parsing
  • Statute lookup
  • Legal mappings
  • Citation verification

The goal is to distinguish between what an LLM claims a statute says and what can be verified against the project's legal knowledge source.


4. Evidence & Confidence

Legal.ai is designed so that extracted information can be associated with supporting source context.

A simplified reliability flow is:

Extraction
    β”‚
    β–Ό
Source Evidence
    β”‚
    β–Ό
Validation
    β”‚
    β–Ό
Consistency Checks
    β”‚
    β–Ό
Confidence Score

This provides a more useful signal than simply returning an LLM response.


5. Document Safety

Legal documents are treated as untrusted input.

Before AI processing, the pipeline includes document safety checks intended to reduce risks from malicious or adversarial document content.

PDF
 β”‚
 β–Ό
Safety Check
 β”‚
 β”œβ”€β”€ Unsafe β†’ Reject
 β”‚
 └── Safe
      β”‚
      β–Ό
   AI Pipeline

πŸ› οΈ Tech Stack

Technology Role
Python 3.12+ Core application
LangGraph Agent/workflow orchestration
LangChain LLM application framework
OpenAI LLM-powered processing
Docling PDF/document parsing
Qdrant Vector database and semantic retrieval
PostgreSQL / Supabase Persistent application data
SQLAlchemy Database access
Sentence Transformers Embeddings
FlagEmbedding Embedding and retrieval models
Pydantic Structured data validation
Langfuse LLM observability and tracing
Docker Reproducible execution environment

πŸ“ Project Structure

Legal.ai/
β”‚
β”œβ”€β”€ data/                   # Data and supporting resources
β”œβ”€β”€ db/                     # Database schema and utilities
β”‚
β”œβ”€β”€ docs/
β”‚   └── architecture/       # Architecture documentation
β”‚
β”œβ”€β”€ observability/          # LLM tracing and observability
β”‚
β”œβ”€β”€ pipeline/
β”‚   β”œβ”€β”€ agents/             # Specialized processing agents
β”‚   β”œβ”€β”€ chunking.py         # Document chunking
β”‚   β”œβ”€β”€ embeddings.py       # Embedding generation
β”‚   β”œβ”€β”€ graph.py            # LangGraph workflow
β”‚   β”œβ”€β”€ validation.py       # Output validation
β”‚   β”œβ”€β”€ confidence.py       # Confidence scoring
β”‚   β”œβ”€β”€ pdf_safety.py       # PDF safety checks
β”‚   β”œβ”€β”€ statute_verification.py
β”‚   └── run.py              # Pipeline entry point
β”‚
β”œβ”€β”€ schemas/                # Pydantic schemas
β”œβ”€β”€ scripts/                # Utility/setup scripts
β”‚
β”œβ”€β”€ statute_kb/
β”‚   β”œβ”€β”€ acts.py             # Legal acts registry
β”‚   β”œβ”€β”€ ingest.py           # Knowledge-base ingestion
β”‚   β”œβ”€β”€ lookup.py           # Statute retrieval
β”‚   β”œβ”€β”€ mappings.py         # Legal mappings
β”‚   └── parser.py           # Statute parsing
β”‚
β”œβ”€β”€ Dockerfile
β”œβ”€β”€ docker-compose.yml
β”œβ”€β”€ pyproject.toml
└── README.md

πŸ”„ Processing Pipeline

Step 1 β€” Ingestion

A court judgment PDF is supplied to the pipeline.

Step 2 β€” Safety Validation

The document is checked before it enters the AI workflow.

Step 3 β€” Parsing

Docling extracts usable text and document structure.

Step 4 β€” Chunking

Long documents are divided into retrieval-friendly sections.

Step 5 β€” Agentic Extraction

Specialized workflow stages identify information such as:

  • Case metadata
  • Facts
  • Legal issues
  • Arguments
  • Evidence
  • Statutory references

Step 6 β€” Retrieval & Verification

Relevant information is retrieved from the vector store and statute knowledge base.

Step 7 β€” Validation

The extracted information is checked against available source context and validation rules.

Step 8 β€” Confidence Scoring

The pipeline produces confidence signals for the resulting information.

Step 9 β€” Structured Output

The final result is returned in a structured, machine-readable format.


πŸ“Š Example Output

A processed judgment can be represented in a structure similar to:

{
  "case_metadata": {
    "case_name": "...",
    "court": "...",
    "date": "...",
    "case_number": "..."
  },
  "facts": [
    "...",
    "..."
  ],
  "issues": [
    "..."
  ],
  "arguments": {
    "petitioner": [],
    "respondent": []
  },
  "statutes": [
    {
      "act": "...",
      "section": "...",
      "verified": true
    }
  ],
  "evidence": [
    {
      "claim": "...",
      "source": "..."
    }
  ],
  "confidence": 0.0
}

The exact schema and fields depend on the document and pipeline configuration.


πŸ“¦ Installation

Prerequisites

  • Python 3.12+
  • Docker
  • Docker Compose
  • PostgreSQL / Supabase
  • Required LLM/API credentials

1. Clone the repository

git clone https://github.com/vineeethh/Legal.ai.git
cd Legal.ai

2. Configure environment variables

Create your environment file:

cp .env.example .env

Add the required API and database credentials to .env.

Never commit API keys or other secrets to GitHub.

3. Start the services

docker compose up -d qdrant

Qdrant is exposed on:

http://localhost:6333

4. Build the application

docker compose build

5. Initialize the database

docker compose run --rm app python -m db.apply_schema

▢️ Running the Pipeline

Process a legal judgment with:

docker compose run --rm app python -m pipeline.run path/to/judgment.pdf

The supported Docker workflow keeps document-processing dependencies and model caches inside the containerized environment.


πŸ”­ Observability

Legal.ai integrates Langfuse to provide visibility into LLM workflows.

Observability can help with:

  • Prompt/response tracing
  • Workflow debugging
  • Agent execution analysis
  • Latency monitoring
  • Token/cost analysis
  • Identifying failure points

This is particularly important when developing multi-stage LLM systems where failures can occur at different points in the pipeline.


🎯 Use Cases

Legal.ai can serve as a foundation for:

  • βš–οΈ Legal research assistants
  • πŸ“š Case-law analysis
  • πŸ”Ž Legal information retrieval
  • πŸ“ Judgment summarization
  • πŸ§‘β€βš–οΈ Legal practitioner research tools
  • πŸ—‚οΈ Legal document structuring
  • πŸ›οΈ Compliance and regulatory analysis
  • πŸ€– RAG-based legal applications
  • πŸ“Š Legal analytics platforms

🧠 Areas of Technical Focus

This project combines:

Generative AI Γ— Agentic AI Γ— RAG Γ— NLP Γ— Document Intelligence Γ— Legal Technology

Key areas explored:

  • Large Language Models
  • Multi-Agent Systems
  • LangGraph
  • Retrieval-Augmented Generation
  • Semantic Search
  • Vector Databases
  • Information Extraction
  • Document Intelligence
  • Knowledge Bases
  • LLM Evaluation
  • AI Safety
  • Observability
  • Explainable AI

πŸ—ΊοΈ Roadmap

  • Web-based legal analysis interface
  • Interactive source-to-claim navigation
  • Expanded Indian statute knowledge base
  • Case-law citation graph
  • Human-in-the-loop review interface
  • Automated evaluation benchmarks
  • Regression test suite for legal documents
  • Production-ready API layer
  • Multilingual Indian legal document support
  • Advanced legal precedent retrieval

⚠️ Disclaimer

Legal.ai is an AI research and engineering project and is not a substitute for professional legal advice.

AI-generated or extracted information should always be verified against the original judgment and authoritative legal sources before being used for legal, compliance, or judicial decisions.


🀝 Contributing

Contributions, suggestions, and bug reports are welcome.

  1. Fork the repository.
  2. Create a feature branch:
git checkout -b feature/your-feature
  1. Commit your changes:
git commit -m "Add your feature"
  1. Push the branch:
git push origin feature/your-feature
  1. Open a Pull Request.

⭐ Support

If you find Legal.ai useful or interesting, consider giving the repository a ⭐.


πŸ‘¨β€πŸ’» Author

Vineeth Vuppala

AI/ML β€’ Generative AI β€’ RAG β€’ NLP β€’ Legal AI

GitHub


βš–οΈ Legal.ai

Building more grounded, traceable, and intelligent legal AI systems.

About

Multi-agent case-law analysis with LangGraph supervisor-worker agents, FastAPI, PostgreSQL and Qdrant, with human review for low-confidence output

Topics

Resources

Stars

3 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages