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.

7 min read • View on GitHub • More from shaik-tabassum

An editorial ink illustration of a hand-drawn weighing scale. On the left pan sits a small mechanical calculator spitting a curling paper tape of decimal probabilities. On the right pan sits a hand-written checklist clipped to a board with visible ticked boxes and crossed-out lines. Both pans tip toward a single central brass dial whose needle rests between two engraved zones, with a thin taut wire running from each pan to the dial's pivot. It depicts PayGuard AI's core idea: two independent verdicts, one fused outcome, with the human-readable checklist given equal weight to the machine.
Two independent judgments, one fused number. The system weighs a machine-learning probability against a transparent rule score at a fixed 70/30 split.

AI-powered solution for detecting and preventing digital payment fraud.

shaik-tabassum, Project description on GitHub · shaik-tabassum/PayGuard-AI on GitHub
Key Takeaways

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.

MetricPrior versionRewrite
Accuracy0.7950.911
Fraud precision0.290.52
Fraud recall0.550.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 close-up editorial ink illustration of a coin-sorting funnel. A wide mouth lets a dense stream of identical plain coins pour through. Near the bottom, a narrow adjustable gate has been tightened, and almost every coin slides past it into a large unmarked bin while a single dark, slightly larger coin is caught at the gate and held. On the funnel's rim, a small engraved gauge reads 0.80. It visualizes the accuracy trap: a tighter threshold catches few bad coins and lets most through, producing high precision and low recall while the big unmarked bin does the work of the headline accuracy figure.
Tighten the gate and almost everything slides through. A threshold of 0.801 produces a high precision, low recall model, and the majority class supplies the 91 percent.

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.

ModelCV PR-AUC (mean)Std
Logistic Regression0.4670.039
Random Forest0.4470.019
HistGradientBoosting0.3870.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.

A black ink editorial portrait of the PayGuard AI maintainer, rendered in WSJ hedcut style from their GitHub avatar. Stipple dots form the skin, fine hatching builds the hair and clothing, and the background is pure white. The portrait accompanies the project's one-line GitHub description.

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.

Poke at the fusion. Toggle a rule, drag the model probability, and watch a modest ML score plus a couple of flags push a transaction across a decision band.

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.

ProjectStackSignature ideaSandbox posture
shaik-tabassum/PayGuard-AIPython, FastAPI, scikit-learn, vanilla JS70/30 ML and rule fusion with returned reasonsPrototype. CORS flagged as prototype only
mannanloomba/PayGuardReact/Vite, FastAPI, SQLite, PyMuPDF, TesseractExplainable bill and QR review with bounded AI interpretationHuman-approved actions, no live bank or UPI
Prachi-2407/payguard-aiFastAPI, React, Tailwind, XGBoost, SHAP, NetworkXSimulated ML plus blockchain graph signals and pre-capture assessmentSandbox payment workflow, backend holds decision authority
Sumeet Umbalkar's PayGuard SDKNot disclosedSpend limits, idempotency, and pre-execution policy checks for AI agentsSelf-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.