Skip to content

sharma-sugurthi/SecureShield

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

11 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ›‘οΈ SecureShield

Agentic AI β€” Health Insurance Eligibility & Grievance Engine

License: MIT Python 3.11+ FastAPI Next.js LangGraph Gemini

GenAI-powered health insurance claim eligibility checker & dispute resolution engine for Indian patients.

Claim Guardian Architecture: 4 Specialized Agents Β· 16 Custom Tools Β· Deterministic Decision Engine Β· Zero-Hallucination Verdicts Β· IRDAI 2024 (June) Compliant


πŸ“‘ Table of Contents


✨ Features

Feature Description
πŸ“„ Policy Ingestion Upload any insurance PDF β†’ Agent extracts & freezes rules in seconds
πŸ” AI Eligibility Check Multi-agent pipeline analyzes patient case against frozen policy rules
βš™οΈ Deterministic Verdict 6-phase rule engine with zero LLM involvement in financial math
🧠 Medical Coding Automatic ICD-10-PCS code lookup for 500+ procedures
πŸ™οΈ City-Tier Classification Auto-applies IRDAI Tier 1/2/3 room rent limits based on location
πŸ’° Agentic Savings what_if_analyzer finds cheaper alternatives (e.g., room downgrade tips)
βš–οΈ Grievance Agent Denied claim? Agent generates PDF report, formal letter & sends grievance email
πŸ“š IRDAI Precedents Searches real Ombudsman/NCDRC rulings to strengthen your dispute
πŸ” 51-Point Audit Trail Every agent step logged for compliance transparency
πŸ”„ Multi-Model Failover Auto-switches across 8+ LLM models on rate limits β€” never goes down

πŸ—οΈ Architecture

Full System Flow

flowchart TB
    subgraph INPUT["πŸ“„ Input Layer"]
        PDF["Insurance Policy PDF"]
        CASE["Patient Case Facts"]
    end

    subgraph POLICY_AGENT["πŸ€– Agent 1 β€” Policy Agent (ReAct)"]
        direction TB
        PT1["πŸ“ pdf_text_extractor"]
        PT2["πŸ“Š pdf_table_extractor"]
        PT3["βš–οΈ irdai_regulation_lookup"]
        PT4["βœ… rule_validator"]
        LLM1["🧠 Gemini 2.5 Flash\n(JSON Rule Extraction)"]
        PT1 --> LLM1
        PT2 --> LLM1
        PT3 --> LLM1
        LLM1 --> PT4
    end

    subgraph CASE_AGENT["πŸ€– Agent 2 β€” Case Agent (ReAct)"]
        direction TB
        CT1["πŸ₯ medical_term_normalizer"]
        CT2["πŸ”¬ icd_procedure_lookup"]
        CT3["πŸ™οΈ city_tier_classifier"]
        CT4["πŸ’° hospital_cost_estimator"]
        CT1 --> CT2 --> CT3 --> CT4
    end

    subgraph ENGINE["βš™οΈ Decision Engine (Deterministic)"]
        direction TB
        DE["6-Phase Rule Evaluator\n(Zero LLM β€” Zero Hallucination)"]
        PHASE["β‘  Exclusions β†’ β‘‘ Room Rent β†’ β‘’ Sub-limits\nβ‘£ Waiting Periods β†’ β‘€ Deductibles β†’ β‘₯ Co-pays"]
        DE --> PHASE
    end

    subgraph EXPLAIN_AGENT["πŸ€– Agent 3 β€” Explanation Agent (ReAct)"]
        direction TB
        ET1["πŸ“– clause_explainer"]
        ET2["πŸ’‘ savings_calculator"]
        ET3["πŸ”„ what_if_analyzer"]
        LLM2["🧠 Gemini 2.5 Flash\n(Patient-Friendly Language)"]
        ET1 --> ET2 --> ET3 --> LLM2
    end

    subgraph GRIEVANCE_AGENT["πŸ€– Agent 4 β€” Grievance Agent (ReAct)"]
        direction TB
        GA1["πŸ” search_irdai_precedents"]
        GA2["✍️ draft_grievance_letter"]
        GA3["πŸ“„ generate_claim_report_pdf"]
        GA4["πŸ“§ send_grievance_email"]
        GA1 --> GA2 --> GA3 --> GA4
    end

    subgraph OUTPUT["πŸ“‹ Output"]
        VERDICT["βœ… Verdict (Approved / Partial / Denied)"]
        EXPLAIN["πŸ“ Plain-English Explanation"]
        SAVINGS["πŸ’° Cost-Saving Suggestions"]
        PDF_R["πŸ“„ PDF Claim Report"]
        LETTER["βœ‰οΈ Formal Grievance Letter"]
    end

    PDF --> POLICY_AGENT
    POLICY_AGENT -->|"Frozen Rules (JSON)"| DB[(SQLite)]
    CASE --> CASE_AGENT
    DB --> ENGINE
    CASE_AGENT -->|"Structured Facts"| ENGINE
    ENGINE -->|"Rule-by-Rule Verdict"| EXPLAIN_AGENT
    EXPLAIN_AGENT --> VERDICT & EXPLAIN & SAVINGS
    ENGINE -->|"Partial/Denied"| GRIEVANCE_AGENT
    GRIEVANCE_AGENT --> PDF_R & LETTER

    style POLICY_AGENT fill:#0f3460,stroke:#e94560,color:#ffffff
    style CASE_AGENT fill:#0f3460,stroke:#16213e,color:#ffffff
    style ENGINE fill:#533483,stroke:#e94560,color:#ffffff
    style EXPLAIN_AGENT fill:#0f3460,stroke:#16213e,color:#ffffff
    style GRIEVANCE_AGENT fill:#7b2d00,stroke:#e94560,color:#ffffff
    style OUTPUT fill:#1a1a2e,stroke:#00d2ff,color:#ffffff
Loading

LangGraph State Machine

stateDiagram-v2
    [*] --> LoadPolicy: Start
    LoadPolicy --> AnalyzeCase: Policy loaded
    AnalyzeCase --> DecisionEngine: Facts structured
    DecisionEngine --> ExplainVerdict: Verdict produced
    ExplainVerdict --> GrievanceAgent: Claim denied/partial
    ExplainVerdict --> [*]: Claim approved
    GrievanceAgent --> [*]: Grievance package sent

    state DecisionEngine {
        [*] --> CheckExclusions
        CheckExclusions --> ApplyRoomRent
        ApplyRoomRent --> ApplySublimits
        ApplySublimits --> CheckWaiting
        CheckWaiting --> ApplyDeductibles
        ApplyDeductibles --> ApplyCopay
    }
Loading

πŸ€– Agents & Tools

SecureShield has 4 specialized agents with 16 custom domain tools.

Agent 1 β€” Policy Agent

Reads insurance PDF β†’ extracts & validates structured rules

# Tool Purpose
1 pdf_text_extractor Extract raw text from insurance PDF (PyMuPDF)
2 pdf_table_extractor Extract tables from PDF (premium plans, limits)
3 irdai_regulation_lookup Cross-reference clauses with IRDAI regulations KB
4 rule_validator Validate and freeze extracted rules into SQLite

Agent 2 β€” Case Agent

Enriches raw patient case with medical coding and location intelligence

# Tool Purpose
5 medical_term_normalizer Expand abbreviations (CABG β†’ Coronary Artery Bypass)
6 icd_procedure_lookup Map procedure β†’ ICD-10-PCS code (500+ procedures)
7 city_tier_classifier Auto-classify city β†’ IRDAI Tier 1/2/3 for room rent
8 hospital_cost_estimator Benchmark procedure cost vs regional market rates

Agent 3 β€” Explanation Agent

Translates verdict into plain language + finds savings

# Tool Purpose
9 clause_explainer Explain each triggered rule in simple language
10 savings_calculator Find max savings via room downgrade or alternatives
11 what_if_analyzer Re-run engine with modified params to show options
12 audit_trail_logger Log every agent step for compliance traceability

Agent 4 β€” Grievance Agent ⭐ New

Turns a "No" into a formal dispute with legal backing

# Tool Purpose
13 search_irdai_precedents Google Search + curated IRDAI/NCDRC/SC rulings
14 draft_grievance_letter LLM drafts formal letter citing IRDAI regulations
15 generate_claim_report_pdf Professional PDF report with rule-by-rule breakdown
16 send_grievance_email Sends grievance to insurer GRO (mocked with tracking ID)

βš–οΈ Compliance Guardrails

SecureShield enforces IRDAI 2024 Master Circular rules deterministically β€” no LLM guesswork.

πŸ›οΈ The "Symbolic Shield" (Why We Don't Hallucinate)

LLM Agent        β†’   Extracts parameters from unstructured PDF
Deterministic Engine β†’   Applies EXACT financial math (no LLM)
Guardrail        β†’   LLM never performs final math or verdict

Key Regulatory Rules Implemented

Rule Implementation
5-Year Moratorium Moratorium Period (IRDAI June 2024): Claims after 60 continuous months cannot be denied for PED/non-disclosure.
Waiting Periods Procedure-specific validation (e.g., Joint Replacement: 4yr, Cataract: 2yr) per 2024 norms.
Room Rent Proportional Deduction Correctly applied per IRDAI PPHI Regulations 2017 (Section 7)
Age-Based Co-pay 20% co-payment auto-triggered for patients aged 60+
City-Tier Limits Tier 1/2/3 room rent caps automatically applied based on hospital location

IRDAI Regulations Cited in Grievance Letters

  • IRDAI (Protection of Policyholders' Interests) Regulations 2017
  • IRDAI Health Insurance Master Circular 2024
  • IRDAI (Insurance Ombudsman) Rules 2017
  • Consumer Protection Act 2019 (Section 2(46))

πŸ§ͺ Verified Test Results

βœ… Case 1 β€” Star Health Premier Gold (β‚Ή10L SI)

Parameter Value
Patient Rajesh Kumar, 45M
Procedure Total Knee Arthroplasty
Hospital Apollo Hospital, Hyderabad (Tier 1)
Room Semi-Private @ β‚Ή4,500/day Γ— 5 days
Total Claim β‚Ή3,25,000
Rules Extracted 32
Verdict βœ… APPROVED β€” 100% coverage
Eligible Amount β‚Ή3,25,000
Pipeline Time ~16.5 sec (12 tools)

⚠️ Case 2 β€” ICICI Lombard Basic Shield (β‚Ή3L SI)

Parameter Value
Patient Amit Shah, 32M
Procedure Appendectomy (Emergency)
Hospital Fortis Hospital, Jaipur (Tier 2)
Room Private @ β‚Ή10,000/day Γ— 3 days
Total Claim β‚Ή1,50,000
Rules Extracted 23
Verdict ⚠️ PARTIAL β€” 66.4% coverage
Eligible Amount β‚Ή99,600 (room rent capped at 1% SI/day)
Agentic Savings πŸ’‘ Switch to Semi-Private β†’ +β‚Ή18,000 saved

βš–οΈ Case 3 β€” ICICI Lombard (Dispute Flow)

Parameter Value
Verdict PARTIAL (flagged for dispute)
Grievance Tools search_irdai_precedents β†’ draft_grievance_letter β†’ generate_claim_report_pdf β†’ send_grievance_email
PDF Report Generated (~3KB, professional layout)
Email Status Sent to grievance@icicilombard.com (Tracking: GRV-B780AED2)
IRDAI Precedents 4 relevant Ombudsman rulings cited

πŸ”„ LLM Resilience β€” Multi-Model Failover

gemini-2.0-flash β†’ gemini-2.5-flash β†’ gemini-2.5-pro β†’ gemini-2.0-flash-lite
       ↓ (if all exhausted)
openrouter/mistral β†’ openrouter/llama β†’ openrouter/deepseek

Global retry: 3 attempts Γ— 60s exponential backoff. The pipeline self-heals on rate limits.


πŸ› οΈ Tech Stack

Layer Technology
Backend Python 3.11+, FastAPI, Pydantic v2, LangGraph 0.2
LLM Provider Google AI Studio (Gemini 2.5 Flash/Pro) + OpenRouter
Frontend Next.js 16, React 19, Vanilla CSS
Database Async SQLite (aiosqlite)
PDF Parsing PyMuPDF (text + table extraction)
PDF Generation ReportLab (professional claim reports)
Knowledge Bases IRDAI regulations, ICD-10-PCS procedures, Indian city tiers
Security HMAC API keys, rate limiting, PDF sanitization

πŸš€ Quick Start

Prerequisites

1. Backend

cd backend
pip install -r requirements.txt

# Add your API key
echo "GOOGLE_API_KEY=your-key-here" > .env

# Start server (note the Master API Key in output)
uvicorn main:app --port 8000

2. Frontend

cd frontend
npm install
npm run dev
# β†’ Open http://localhost:3000

3. Usage

  1. Settings β†’ paste the API key from the backend console
  2. Upload Policy β†’ drag any health insurance PDF
  3. Check Eligibility β†’ fill patient details β†’ instant verdict + savings tips
  4. Dispute Claim β†’ pick a partial/denied claim β†’ AI generates PDF report + formal letter

πŸ“‘ API Reference

Method Endpoint Description Auth
GET /api/health Health check ❌
POST /api/upload-policy Upload & ingest policy PDF βœ…
GET /api/policies List ingested policies βœ…
GET /api/policies/{id} Policy details + extracted rules βœ…
POST /api/check-eligibility Run full agentic eligibility pipeline βœ…
GET /api/history Recent eligibility check history βœ…
GET /api/audit-trail 51-point agent audit trail βœ…
POST /api/dispute-claim πŸ†• Run Grievance Agent pipeline βœ…
GET /api/download-report/{file} πŸ†• Download generated PDF report βœ…

All authenticated endpoints require the X-API-Key header.


πŸ“‚ Project Structure

SecureShield/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ agents/
β”‚   β”‚   β”œβ”€β”€ orchestrator.py        # LangGraph state machine (main pipeline)
β”‚   β”‚   β”œβ”€β”€ policy_agent.py        # Agent 1: PDF β†’ structured rules
β”‚   β”‚   β”œβ”€β”€ case_agent.py          # Agent 2: Patient case analysis
β”‚   β”‚   β”œβ”€β”€ explanation_agent.py   # Agent 3: Verdict explanation + savings
β”‚   β”‚   β”œβ”€β”€ grievance_agent.py     # Agent 4: Dispute letter + PDF + email  ⭐ NEW
β”‚   β”‚   └── model_router.py        # Multi-model LLM failover chain
β”‚   β”œβ”€β”€ engine/
β”‚   β”‚   └── decision_engine.py     # 6-phase deterministic evaluator
β”‚   β”œβ”€β”€ tools/
β”‚   β”‚   β”œβ”€β”€ policy_tools.py        # Tools 1-4: PDF extraction, rule validation
β”‚   β”‚   β”œβ”€β”€ case_tools.py          # Tools 5-8: Medical coding, cost estimation
β”‚   β”‚   β”œβ”€β”€ explanation_tools.py   # Tools 9-12: Clause explainer, what-if
β”‚   β”‚   β”œβ”€β”€ grievance_tools.py     # Tools 13-16: PDF, letter, search, email  ⭐ NEW
β”‚   β”‚   └── audit_tools.py         # Compliance audit logging
β”‚   β”œβ”€β”€ knowledge/
β”‚   β”‚   β”œβ”€β”€ irdai_rules.json       # IRDAI Master Circular 2024 clause KB
β”‚   β”‚   └── icd_procedures.json    # 500+ ICD-10-PCS procedures
β”‚   β”œβ”€β”€ models/
β”‚   β”‚   β”œβ”€β”€ policy.py              # Policy schema
β”‚   β”‚   β”œβ”€β”€ case.py                # CaseFacts schema (with tenure, renewal)
β”‚   β”‚   β”œβ”€β”€ verdict.py             # Verdict, RuleMatch schemas
β”‚   β”‚   └── grievance.py           # GrievanceRequest/Response  ⭐ NEW
β”‚   β”œβ”€β”€ db/                        # Async SQLite
β”‚   β”œβ”€β”€ generated_reports/         # PDF claim reports (auto-created)
β”‚   β”œβ”€β”€ security.py                # HMAC keys, rate limiting, sanitization
β”‚   β”œβ”€β”€ config.py                  # LLM + system configuration
β”‚   β”œβ”€β”€ main.py                    # FastAPI application (9 endpoints)
β”‚   └── requirements.txt
β”œβ”€β”€ frontend/
β”‚   └── src/app/
β”‚       β”œβ”€β”€ page.js                # Dashboard
β”‚       β”œβ”€β”€ upload/                # Policy upload (drag-and-drop)
β”‚       β”œβ”€β”€ check/                 # Eligibility check form
β”‚       β”œβ”€β”€ dispute/               # ⭐ NEW: Grievance Agent UI
β”‚       β”œβ”€β”€ history/               # Past check results
β”‚       β”œβ”€β”€ audit/                 # Agent audit trail viewer
β”‚       └── settings/              # API key configuration
β”œβ”€β”€ LICENSE
└── README.md

πŸ” Security

Layer Implementation
API Auth HMAC-SHA256 generated keys with constant-time comparison
Rate Limiting Per-IP request throttling middleware
PDF Validation Size check (20MB), magic bytes, MIME type before processing
Log Masking API keys never appear in log output
Path Traversal os.path.basename() enforced on all file downloads

πŸ† Hackathon Alignment

Criteria SecureShield Implementation
Innovation Neuro-symbolic ReAct + LangGraph + Consumer Advocacy Agent
Domain Depth ICD-10 coding, IRDAI 2024 compliance, City-Tier classification
Technical Depth 16 custom tools, multi-model failover, async SQLite, PDF generation
Feasibility Deterministic engine β€” zero hallucination risk in financial math
Scalability Multi-provider LLM chain (Google + OpenRouter) β€” never rate-limited
Compliance IRDAI 2024 guardrails, 8-yr moratorium, Ombudsman escalation path

πŸ… Key Design Decisions

Decision Why
Deterministic Decision Engine Financial verdicts must be reproducible & auditable β€” LLMs hallucinate numbers
LLM only for NLP tasks AI does what it excels at (extraction/explanation); math stays in code
Frozen rules in SQLite Once extracted, rules are immutable β€” same case always β†’ same verdict
16 domain-specific tools Purpose-built tools (IRDAI lookup, ICD-10 resolver) beat generic search
Grievance Agent Transforms "Denied" into a legally-backed action β€” unique differentiator
Multi-model failover 8+ models across 2 providers β€” free-tier rate limits are never a showstopper

πŸ“œ License

Licensed under the MIT License β€” see LICENSE for details.


Built for the ET GenAI Hackathon 2026 πŸš€

4 Agents Β· 16 Tools Β· Zero Hallucination Β· Full Compliance

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors