Skip to content
All projects

Personal project · public or synthetic data

FraudGuard

Fraud detection from point-in-time features to an LLM agent that investigates alerts, with deterministic guardrails.

Key results

PR-AUC, LightGBM
0.905
PR-AUC, expert rules
0.426
precision at the block threshold
0.92
scoring latency p50 (laptop CPU)
28 ms

Rare, costly, and it must explain itself

Card fraud is rare (0.25 % of transactions), expensive to miss, and expensive to over-flag: every false alert lands in an analyst’s queue. The model also has to explain itself, and the explanation has to be computed the same way online and offline.

A public rebuild of client work

A public reconstruction, on synthetic data, of an architecture I built as a freelancer for a microfinance institution. No client code or data is used.

From features to an investigating agent

Point-in-time features (velocity, novelty, ratios) → LightGBM, compared with logistic regression and weighted expert rules → a real-time FastAPI service that returns its reasons: the rules fired and the top SHAP contributions.

PSI drift monitoring with a retraining trigger, MLflow tracking, Prometheus metrics, CI with ruff, pytest and a Docker smoke test.

A LangGraph agent that investigates alerts through an MCP server exposing the case data (labels removed), writes a structured report validated by Pydantic, then hands it to deterministic policy code.

On days the model never saw

Chronological split: train on days 30–90, thresholds on days 90–105, test on days 105–120 (71k transactions, 142 frauds). PR-AUC 0.905 for LightGBM against 0.644 for logistic regression and 0.426 for the expert rules.

Block threshold, chosen on validation from a 90 % precision constraint: precision 0.92, recall 0.89 on test. Scoring latency p50 28 ms, p95 32 ms on a laptop CPU.

Drift scenario with a new fraud pattern: PR-AUC fell from 0.905 to 0.721, and input drift (PSI 1.09 on is_foreign) raised the alarm before the labels arrived.

Agent on 15 deliberately hard alerts (7 frauds): 13 decided without a human, accuracy 0.85 when deciding, 7 of 8 legitimate alerts correctly closed.

Precision-recall curves on the test period: LightGBM well above logistic regression and the expert rules.
Precision-recall curves, test period.Figure produced by the project code
Population stability index per feature in the drift scenario; is_foreign is far above the 0.25 drift line.
Input drift per feature (PSI).Figure produced by the project code

The LLM recommends, code decides

The LLM recommends, code decides. It cannot clear an alert above the block threshold, never blocks a card without a human, and every number it quotes must appear in a tool output: that number-tracing guardrail was added after the agent wrote "3.9×" for a 2.8× ratio.

No train/serve skew. The API computes features by calling the same function on the customer history plus the new transaction, and a test checks online = offline.

Label leakage found and fixed. The first simulator named fraudster devices FRAUD-xxxx, so the agent could read the answer. Device ids are now opaque hashes, enforced by a test.

PR-AUC, not ROC-AUC. At 0.25 % prevalence ROC-AUC flatters the model (0.994 here, while PR-AUC is 0.905).

Blind spot and simplifications

Stealth fraud (own device, home country, plausible amount) is caught 20 % of the time at the review threshold, and the agent inherits that blind spot: the 2 frauds it wrongly cleared are both stealth. Its value is triage and report-writing, not the final decision.

The data is synthetic; streaming ingestion (CDC → Debezium → Kafka) and the Redis feature store are replaced by files and an in-memory store in this public version. The agent evaluation uses 15 alerts (free-tier rate limits).