AI Risk Manager for Merchant Loss Intelligence
Don't just score risky transactions. Understand how losses form, spread, and how to stop them.
LossGraph is an AI-powered merchant risk intelligence system that detects, investigates and responds to emerging loss events across transactions, returns, refunds, chargebacks and coordinated abuse.
Unlike conventional fraud models that assign a risk score to individual transactions, LossGraph treats merchant risk as a temporal, relational and evolving phenomenon, building a continuously updated Merchant Risk Graph that connects transactions, customers, orders, devices, addresses, payment instruments, products, returns, refunds, and chargebacks.
Command Center -- every row is a Loss Event, not a flagged transaction; exposure, confidence and recommended action all economically derived, not threshold cutoffs.
Incident detail -- the "How the confidence score was computed" panel breaks the fused confidence back down into the three engines that produced it, the evidence chain traces every claim to a real number, and the AI Investigator writes an evidence-grounded case file (Gemini, citation-checked, never sees ground truth).
Chargeback Responder -- 172 disputes get an evidence checklist and a CONTEST/ACCEPT/ESCALATE recommendation, cross-referenced against this system's own prior detection.
Chargeback case detail -- a dispute already linked to a Loss Event is recommended for ACCEPT, not contested, with the contradiction and reasoning spelled out.
How It Works -- a plain-language walkthrough of the full pipeline, grounded in the same honest evaluation numbers as docs/EVALUATION.md.
- Transaction Intelligence: LightGBM risk model on leakage-safe, pre-authorization features
- Network Intelligence: NetworkX entity graph detecting coordinated abuse clusters, empirically separated from legitimate shared-device patterns (
docs/EVALUATION.md) - Temporal Intelligence: Poisson-style anomaly detection on merchant-level return/dispute rates, the only signal that catches chargeback waves
- Risk Fusion: noisy-OR combination of all three, interpretable back to source
- Loss Event Genome: structured, evidence-chained incidents (not raw transaction scores) with exposure estimates
- Counterfactual Reasoning: 6-policy simulation per event, economically-optimal action recommendation
- AI Investigator: Gemini writes an evidence-grounded case-file narrative per event (citation-checked, never sees ground truth, cannot override the deterministic recommendation), with a verified deterministic fallback when no API key is configured
- Chargeback Responder: evidence checklist + contradiction detection per dispute, cross-referenced against this system's own loss-event detection -- 74/74 ACCEPT recommendations verified correct against ground truth, each linked back to the Loss Event it traces to
- Dashboard: Command Center -> incident drill-down with evidence chain, entity graph, AI investigation, linked chargebacks, policy comparison; a separate Chargebacks section
Synthetic data generator -> 3 intelligence engines -> fusion -> loss events
-> counterfactual simulator -> FastAPI -> Next.js dashboard
Full diagram and design rationale in docs/ARCHITECTURE.md.
lossgraph/
├── backend/ # FastAPI backend (serves precomputed pipeline output)
├── frontend/ # Next.js dashboard
├── ml/ # The three intelligence engines + fusion + loss events + counterfactual simulator
├── data/ # Synthetic data generator + generated dataset
└── docs/ # Architecture, evaluation, data model, API reference
- Framework: FastAPI
- Graph: NetworkX
- Models: LightGBM
- Explainability: SHAP
- Time-series: NumPy, Pandas, SciPy (custom Poisson rolling z-score)
- AI Investigator: Google Gemini (
google-genai, Pydantic structured output viaresponse_schema), deterministic fallback
- Framework: Next.js (App Router) + TypeScript + Tailwind CSS
- Visualization: Cytoscape.js (entity graph)
- Python 3.10+
- Node.js 18+
Generates the synthetic merchant ecosystem and runs all three engines + fusion + loss event detection + counterfactual simulation. The backend serves this output; it does not recompute it per request.
pip install -r backend/requirements.txt
make pipelinecd backend
python -m uvicorn app.main:app --reloadcd frontend
npm install
npm run devOpen http://localhost:3000 for the Command Center.
- Quick Start -- get it running, with troubleshooting
- Architecture -- what was built, what was cut, and why
- Evaluation -- held-out precision/recall, economic evaluation, stated limitations
- Data Model
- API Reference
- Roadmap -- the real day-by-day build log
- Data Generator Design, ML Engine Design -- design decisions and bugs found/fixed along the way
No automated test suite yet -- correctness for the ML pipeline is
established by held-out evaluation instead (docs/EVALUATION.md), and the
frontend was verified with a real headless-browser pass rather than unit
tests. Both are gaps worth closing past the buildathon deadline, not
hidden.
# Frontend production build (type-checks + lints on build)
cd frontend && npm run build- Risk is not a score. Risk is a changing system.
- Evidence-based decisions - All claims traceable to underlying data
- Economic optimization - Actions minimize expected merchant loss
- Robustness - Conservative under legitimate-but-unusual behavior
- Transparency - Complete audit trails and explainability
Primary metric is expected loss reduction, not accuracy. Full held-out
precision/recall, economic evaluation, and honestly-stated limitations are
in docs/EVALUATION.md.
Built solo for the Razorpay AI Buildathon, Track 02: AI Risk Manager.




