PayGuard AI Fuses a Black Box and a Checklist to Score Fraud
A 70/30 blend of machine learning and hand-written rules, plus the uncomfortable lesson hiding in its own metrics file.

AI-powered solution for detecting and preventing digital payment fraud.
- PayGuard AI scores every transaction twice, fusing a 70/30 blend of an ML probability and a transparent rule score into one 0 to 100 risk number.
- The project's own metrics file documents the accuracy trap: the rewrite lifted headline accuracy from 79.5% to 91.1% while fraud recall fell from 0.55 to 0.39.
- Selecting on cross-validated PR-AUC picked the simplest model, Logistic Regression, over Random Forest by a margin smaller than the winner's own standard deviation.
- The sanitize layer fills missing fields with defaults, so a missing amount contributes zero risk in a system built to catch fraud.
Two Verdicts, One Number
Most fraud models give you a number and call it a day. PayGuard AI gives you a number, a second opinion, and a receipt.
Every transaction that hits the API is scored twice. A trained scikit-learn pipeline produces a machine-learning fraud probability. An independent rule engine reads the same fields through a hand-written checklist: amount, new device, location change, velocity, account age, prior fraud. The two verdicts are fused at a fixed split, 70 percent model and 30 percent rules.
The result lands in a band. Zero to 30 is LOW and APPROVE. Thirty-one to 70 is MEDIUM and REVIEW. Seventy-one to 100 is HIGH and BLOCK. Along with the score, the API returns the reasons behind the rule contribution, so a reviewer can see exactly which signals fired.
That last part is the point. The ML side stays opaque. The rule side is legible, and the system hands you its reasoning in the response instead of making you reconstruct it.
The Accuracy Trap in Its Own Metrics File
The repo ships a model_metrics.json file, and it is more interesting than the README that points at it.
The prior version of the model reported 79.5 percent accuracy. The rewrite reports 91.1 percent. That looks like a clean win until you read the fraud-specific numbers sitting next to it. Fraud recall, the share of actual fraud the model catches, fell from 0.55 to 0.39. The model got better at the headline metric and worse at the job.
| Metric | Prior version | Rewrite |
|---|---|---|
| Accuracy | 0.795 | 0.911 |
| Fraud precision | 0.29 | 0.52 |
| Fraud recall | 0.55 | 0.39 |
What happened is a threshold. The rewrite tunes the decision cutoff to 0.801 instead of the default 0.5. Push the bar that high and the model predicts "not fraud" for almost everything, which is correct most of the time because most transactions are legitimate. The 91 percent is the majority class wearing a costume.
Precision rose from 0.29 to 0.52, so the flags it does raise are more often right. That is a real trade, recall for precision, and it is a defensible one. The problem is that the README frames the rewrite as an unambiguous improvement. The metrics file tells a more careful story.
There is a second reason to read these numbers with caution. The test set holds roughly 23 fraud cases. Precision of 0.522 is 12 out of 23. Recall of 0.391 is 9 out of 23. A few transactions move every decimal place.
A Rewrite Built to Refuse the Easy Answer
The rewrite did not stumble into those numbers. It was built to stop optimizing the wrong thing, and the train_model.py docstring says so plainly.
The prior version scored well on accuracy and badly on fraud. The new version changes five decisions at once. It sets class_weight="balanced" on every candidate. It compares three model families instead of one. It selects on cross-validated PR-AUC, not accuracy. It tunes the decision threshold. And it uses a stratified split to hold the fraud rate steady across folds.
| Model | CV PR-AUC (mean) | Std |
|---|---|---|
| Logistic Regression | 0.467 | 0.039 |
| Random Forest | 0.447 | 0.019 |
| HistGradientBoosting | 0.387 | 0.027 |
The honest surprise is in that table. Logistic Regression, the simplest candidate, won. Random Forest came second, and the gradient booster came last. The assumption that a bigger model would do better did not survive contact with the data.
And the ranking is not decisive. Logistic Regression's margin over Random Forest is 0.020. Its own standard deviation is 0.039. The winner is ahead by less than its own noise, which is exactly the kind of result a project should report and most do not.
The Parts That Actually Hold Up
Strip away the product framing and the engineering underneath is small, mostly sensible, and worth copying.
preprocess.py is the single source of truth for features. Both training and inference import the same constants and build the same Pipeline, which is how you stop training-serving skew before it starts. The one-hot encoder is set to handle_unknown="ignore", so an unseen location at inference time gets a zero row instead of an exception.
risk_engine.py loads the model once at startup. If the artifact is missing, it raises a ModelNotLoadedError with a message telling you to run the training script. That is fail-fast done right.
ML_WEIGHT = 0.70
RULE_WEIGHT = 0.30
LOW_MAX = 30
MEDIUM_MAX = 70
The saved artifact is self-describing: the pipeline, the tuned threshold, and the feature list are pickled together. Inference does not have to guess which threshold the model was tuned for, because the threshold travels with the model.
Every transaction also passes through a _sanitize step before scoring. Missing fields get documented defaults, and each fix is recorded in a warnings list that comes back in the API response. Nothing disappears silently, which is more than most prototypes manage.
Where It Fails Open
The sanitize layer has a sharp edge. When amount is missing, it defaults to 0.0.
In a fraud system, that means a transaction with no amount recorded contributes zero risk from the largest single rule signal. The system fails open. A missing field is treated as harmless rather than suspicious, and the warnings list is the only clue that anything was off.
That is a design choice, not a bug, but it is the kind of choice a fraud team would argue about for a week. The safer default is usually to treat missing data as its own risk signal, or to refuse to score the transaction and route it straight to review.
There is a smaller issue in the data path. clean_dataframe() median-imputes numeric columns across the full dataset before the train and test split, so the median used for imputation has seen test rows. The scaler and encoder are fit correctly inside the pipeline on training folds only, so the leakage is minor. It still sits awkwardly next to the "NO DATA LEAKAGE" claim in the training docstring.
Three Projects Named PayGuard
Search for PayGuard and you will find several payment-safety projects sharing the name. They are not forks of each other, and nothing links them beyond the label.
| Project | Stack | Signature idea | Sandbox posture |
|---|---|---|---|
| shaik-tabassum/PayGuard-AI | Python, FastAPI, scikit-learn, vanilla JS | 70/30 ML and rule fusion with returned reasons | Prototype. CORS flagged as prototype only |
| mannanloomba/PayGuard | React/Vite, FastAPI, SQLite, PyMuPDF, Tesseract | Explainable bill and QR review with bounded AI interpretation | Human-approved actions, no live bank or UPI |
| Prachi-2407/payguard-ai | FastAPI, React, Tailwind, XGBoost, SHAP, NetworkX | Simulated ML plus blockchain graph signals and pre-capture assessment | Sandbox payment workflow, backend holds decision authority |
| Sumeet Umbalkar's PayGuard SDK | Not disclosed | Spend limits, idempotency, and pre-execution policy checks for AI agents | Self-hosted or local evaluation |
Each one picks a different problem. mannanloomba/PayGuard reviews bills and QR codes and keeps a human in the loop before any action. Prachi-2407/payguard-ai layers pre-capture assessment with simulated ML and blockchain graph signals. Sumeet Umbalkar's SDK guards AI agent spending with policy checks and idempotency. These are comparison points, not verified inspirations or descendants of the target.
shaik-tabassum's version is the smallest and the most transparent of the set. It is a classroom-shaped prototype that happens to document one of the most important lessons in applied machine learning. The fusion is the product. The metrics file is the education.





