Skip to content

About

Four specialised LLM agents adjudicate health-insurance claims with clause-grounded audit trails.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Latest commit

 

History

59 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

title Policy-Aware Claim Decision Engine
emoji 🛡️
colorFrom blue
colorTo green
sdk docker
app_port 7860

Policy-Aware Multi-Agent RAG Claim Decision Engine

⭐ Multi-agent RAG for policy-aware claim verification. Please star the project if you find it innovative!

GitHub Stars Python 3.11 FastAPI Streamlit LangGraph

A production-style AI system that analyzes health-insurance claim cases using Retrieval-Augmented Generation (RAG) and a genuine multi-agent workflow. The policy document is treated as the sole authoritative source of truth.


🌐 Live Deployment & Interactive Demo

The system is deployed and accessible via cloud endpoints and local development URLs:

Service Endpoint / URL Description
Hugging Face Space (Direct App) https://aniketnew7-claim-decision-engine.hf.space Direct cloud Docker deployment with Streamlit UI & FastAPI backend
Hugging Face Space (Hub & Logs) https://huggingface.co/spaces/Aniketnew7/claim-decision-engine Hugging Face Space repository, card & build logs
FastAPI Swagger Docs (Local) http://localhost:8000/docs Interactive OpenAPI docs & endpoints (/analyze, /health)
FastAPI Health Check Docs http://localhost:8000/docs#/default/health_check_health_get Interactive health check endpoint in Swagger UI
FastAPI Health Endpoint (Raw JSON) http://localhost:8000/health Live system status & model availability check
Streamlit Interactive UI (Local) http://localhost:8501 Local adjudication interface with real-time agent trace & citations

1. System Architecture

The engine employs a 5-Agent Workflow orchestrated via LangGraph, backed by a Hybrid Retrieval Pipeline (BGE dense embeddings + BM25s sparse index + RRF + Cross-Encoder Reranker).

flowchart TD
    subgraph "Ingestion & Indexing"
        PDF["Policy PDF\n(UNIHLIP18004V011718)"] --> Parser["Section-Aware\nPDF Parser"]
        Parser --> Chunker["Semantic Hierarchy\nChunker"]
        Chunker --> FAISS["FAISS Index\n(BAAI/bge-small-en-v1.5)"]
        Chunker --> BM25["BM25 Index\n(bm25s Lucene + Porter)"]
    end

    subgraph "API & UI Layer"
        UI["Streamlit Frontend\n(Port 7860)"] --> API["FastAPI Backend\n/analyze, /health (Port 8000)"]
    end

    subgraph "LangGraph Multi-Agent Adjudication Workflow"
        API --> CA["1. Case Analysis Agent\n(Extracts facts, defines investigation dimensions)"]
        CA --> PE["2. Policy Evidence Agent\n(Runs parallel dimension-specific hybrid retrieval)"]
        PE --> CE["3. Coverage & Exclusion Agent\n(Grounds decisions on policy clauses, limits, waiting periods)"]
        CE --> DA["4. Decision Agent\n(Synthesizes verdict, limits, citations, evidence confidence)"]
        DA --> VA["5. Validation Agent\n(Verifies claim-evidence fidelity quality gate)"]
        
        VA -->|PASS| FIN["Authoritative Decision Output"]
        VA -->|"FAIL (Retry 1 or 2)"| CE
        VA -->|"Max Retries Exceeded"| ABS["NEEDS_REVIEW Abstention"]
    end

    subgraph "Dimension-Specific Hybrid Retrieval"
        PE -.-> D1["Coverage Query"]
        PE -.-> D2["Waiting Period Query"]
        PE -.-> D3["Exclusions Query"]
        PE -.-> D4["Hospital Definition Query"]
        D1 --> HR["Hybrid Retriever\n(Dense + BM25s)"]
        D2 --> HR
        D3 --> HR
        D4 --> HR
        HR --> RRF["Reciprocal Rank Fusion\n(RRF k=60)"]
        RRF --> RERANK["Cross-Encoder Reranker\n(ms-marco-MiniLM-L-6-v2)"]
        RERANK -.-> PE
    end
Loading

2. Genuine Multi-Agent Workflow

The system enforces strict functional separation:

  1. Case Analysis Agent: Extracts claim parameters and formulates dimension-specific investigation questions. Hard rule: It never makes policy conclusions; it only establishes what must be investigated.
  2. Policy Evidence Agent: Retrieval specialist (no LLM). Executes independent hybrid retrieval queries across each dimension to ensure broad policy clauses do not drown out specific exclusions or waiting periods.
  3. Coverage & Exclusion Agent: Core reasoning agent. Analyzes evidence against claim facts, establishes waiting periods, exclusions, definitions, and category sub-limits.
  4. Decision Agent: Synthesizes specialist findings into the final decision, compiling citations and computing an evidence-based composite confidence score from observable signals.
  5. Validation Agent: Quality gate. Verifies that every key finding is directly supported by its cited policy text. If unsupported claims or hallucinations are detected, it triggers a feedback retry loop.

3. Decision Contract & Statuses

API responses strictly adhere to the structured decision schema:

  • ADMISSIBLE: Full coverage with no material deductions.
  • ADMISSIBLE_WITH_LIMITS: Covered, but subject to room rent caps (1% SI), ambulance limits, or waiting periods.
  • PARTIALLY_ADMISSIBLE: Only eligible procedures covered; non-payable items segregated.
  • NOT_ADMISSIBLE: Policy exclusions (e.g., cosmetic surgery, unproven treatments, initial 30-day waiting period).
  • NEEDS_REVIEW: Abstains safely when evidence is missing (e.g., unverified hospital registration, unknown necessity).

4. Local Setup & Quickstart

Prerequisites

  • Python 3.11+
  • Git

1. Installation

Linux / macOS (Bash):

git clone https://github.com/Aniketchavan7/claim-decision-engine.git
cd claim-decision-engine

# Create & activate virtual environment
python -m venv venv
source venv/bin/activate

# Install dependencies
pip install -r requirements.txt

Windows (PowerShell):

git clone https://github.com/Aniketchavan7/claim-decision-engine.git
cd claim-decision-engine

# Create & activate virtual environment
python -m venv venv
.\venv\Scripts\Activate.ps1

# Install dependencies
pip install -r requirements.txt

Windows (Command Prompt - CMD):

git clone https://github.com/Aniketchavan7/claim-decision-engine.git
cd claim-decision-engine

# Create & activate virtual environment
python -m venv venv
venv\Scripts\activate.bat

# Install dependencies
pip install -r requirements.txt

2. Configure Environment Variables

Create .env from template:

  • Windows PowerShell: Copy-Item .env.example .env
  • Windows CMD: copy .env.example .env
  • Linux / macOS: cp .env.example .env

Edit .env to configure your LLM provider & API key:

LLM_PROVIDER=xkiro
LLM_API_KEY=your-xkiro-or-openai-compatible-api-key
LLM_REASONING_MODEL=qwen/qwen3.8-max:free
LLM_FAST_MODEL=qwen/qwen3.7-flash:free
LLM_FALLBACK_MODEL=minimax/minimax-m3:free

3. Launch Services

Run the backend and frontend in two separate terminal windows:

Terminal 1 — FastAPI Backend (Port 8000)

Run in all environments (Windows PowerShell, CMD, or Linux/macOS):

uvicorn src.api.main:app --host 0.0.0.0 --port 8000 --reload

Verify the backend is live by opening http://localhost:8000/docs.

Terminal 2 — Streamlit Frontend (Port 8501)

Tip

http://localhost:8000 is already configured as the default API_BASE_URL, so you can launch the app with a single simple command!

Easiest (All Platforms - Windows / Mac / Linux):

streamlit run frontend/app.py

If overriding with a custom API_BASE_URL:

  • Windows (PowerShell):
    $env:API_BASE_URL="http://localhost:8000"; streamlit run frontend/app.py
  • Windows (Command Prompt):
    set API_BASE_URL=http://localhost:8000 && streamlit run frontend/app.py
  • Linux / macOS (Bash):
    API_BASE_URL="http://localhost:8000" streamlit run frontend/app.py

5. End-to-End Evaluation Results

The engine was evaluated against all 12 public synthetic benchmark cases and 5 custom stress cases via evaluation/run_evaluation.py. All metrics are dynamically generated from live agent runs with inspectable policy chunk citations and raw UTC timestamps stored in evaluation/results/evaluation_details.json.

Summary Benchmark Metrics

Metric Result Target Benchmark Methodological Basis
Decision Quality (Label Match) 100.0% (17/17) $\ge 85%$ Direct comparison against expected synthetic benchmark labels
Validation Gate Pass Rate 100.0% (17/17) Real-world Claims passing code-level citation resolution & strict LLM grounding
Strict Abstention Accuracy 100.0% (4/4) $100%$ Genuine abstention cases (PUB-006, PUB-011, CUST-001, CUST-004) cleanly identified
Retrieval Section Recall@k 100.0% $\ge 85%$ Canonical policy clause / statutory heading recall across dimensions
Canonical Citation Resolver Accuracy 100.0% $\ge 90%$ Chunks resolved against chunks.json index with verified provenance & text grounding
Material Finding Citation Coverage 98.6% $\ge 80%$ Percentage of key material findings directly backed by inspectable policy citations

Full 17-Case Adjudication Matrix

Case ID Expected System Decision Match Confidence Validation Gate Section Recall Finding Coverage Latency
PUB-001 ADMISSIBLE_WITH_LIMITS ADMISSIBLE_WITH_LIMITS ✅ PASS 1.00 PASS 100% 100% 84.40s
PUB-002 NOT_ADMISSIBLE NOT_ADMISSIBLE ✅ PASS 1.00 PASS 100% 100% 58.71s
PUB-003 NOT_ADMISSIBLE NOT_ADMISSIBLE ✅ PASS 1.00 PASS 100% 100% 66.93s
PUB-004 ADMISSIBLE_WITH_LIMITS ADMISSIBLE_WITH_LIMITS ✅ PASS 0.94 PASS 100% 100% 71.62s
PUB-005 ADMISSIBLE_WITH_LIMITS ADMISSIBLE_WITH_LIMITS ✅ PASS 0.98 PASS 100% 100% 79.28s
PUB-006 NEEDS_REVIEW NEEDS_REVIEW ✅ PASS 0.47 PASS 100% 100% 70.37s
PUB-007 ADMISSIBLE_WITH_LIMITS ADMISSIBLE_WITH_LIMITS ✅ PASS 0.93 PASS 100% 100% 75.90s
PUB-008 NOT_ADMISSIBLE NOT_ADMISSIBLE ✅ PASS 1.00 PASS 100% 100% 65.27s
PUB-009 ADMISSIBLE_WITH_LIMITS ADMISSIBLE_WITH_LIMITS ✅ PASS 1.00 PASS 100% 100% 85.01s
PUB-010 ADMISSIBLE_WITH_LIMITS ADMISSIBLE_WITH_LIMITS ✅ PASS 0.98 PASS 100% 100% 71.86s
PUB-011 NEEDS_REVIEW NEEDS_REVIEW ✅ PASS 0.54 PASS 100% 67% 65.56s
PUB-012 NOT_ADMISSIBLE NOT_ADMISSIBLE ✅ PASS 1.00 PASS 100% 100% 62.79s
CUST-001 NEEDS_REVIEW NEEDS_REVIEW ✅ PASS 0.51 PASS 100% 100% 80.45s
CUST-002 NOT_ADMISSIBLE NOT_ADMISSIBLE ✅ PASS 1.00 PASS 100% 100% 136.80s
CUST-003 ADMISSIBLE_WITH_LIMITS ADMISSIBLE_WITH_LIMITS ✅ PASS 1.00 PASS 100% 100% 84.46s
CUST-004 NEEDS_REVIEW NEEDS_REVIEW ✅ PASS 0.64 PASS 100% 100% 75.27s
CUST-005 PARTIALLY_ADMISSIBLE PARTIALLY_ADMISSIBLE ✅ PASS 0.95 PASS 100% 100% 73.09s

Reproducing Evaluation Results

To re-run the complete evaluation pipeline locally:

python evaluation/run_evaluation.py --output evaluation/results --cases all

Artifacts generated:

  • evaluation/results/evaluation_report.md: Markdown summary table
  • evaluation/results/evaluation_summary.json: Aggregate metrics (Accuracy, Section Recall, Citation Fidelity)
  • evaluation/results/evaluation_details.json: Full case-by-case adjudication trace with retrieved chunk IDs and timestamps.

6. Design Decisions, Trade-offs & Known Limitations

Decision Rationale Trade-off
BGE-small + BM25s Hybrid Dense vectors capture conceptual intent; BM25s captures strict policy clauses and codes. Slight additional indexing time.
Dimension-Specific Retrieval Prevents general hospitalization clauses from dominating specific exclusion or waiting period queries. Makes multiple retrieval passes per claim.
Evidence-Based Confidence Calculates confidence deterministically from evidence coverage, validation results, and missing fields rather than arbitrary LLM output. Not a frequentist statistical probability.
Strict Abstention Policy When hospital credentials or medical necessity are unspecified, forces NEEDS_REVIEW to prevent hallucinated liability. Requires manual human referee intervention on ambiguous claims.

7. Documentation & Deliverables


8. Deployment

A production-ready Dockerfile is provided for zero-friction deployment to Hugging Face Spaces (Docker SDK, 16GB free RAM), Render, or Streamlit Community Cloud.

docker build -t claim-decision-engine .
docker run -p 7860:7860 -e LLM_API_KEY="your-key" claim-decision-engine

About

Four specialised LLM agents adjudicate health-insurance claims with clause-grounded audit trails.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages