Skip to main content

tabular-model-robustness

PyPI CI License: MIT Agent skill Guide

How cheaply can an attacker get past your fraud, bot or abuse model? This tool attacks your own XGBoost, LightGBM or scikit-learn model the way a real attacker would: changing only what they control, within realistic limits, and counting what it costs them. Then it hardens the model and shows the trade-off between accuracy, robustness and inference energy.

pip install "tabular-model-robustness[all]"
tabular-model-robustness attack --model bot_model.json --data recent_traffic.csv --label is_bot --constraints bot-constraints.json --budgets 1,5,10
tabular-model-robustness demo
Robustness, accuracy and inference cost

  model                     AUC  recall  evaded  median cost  ms/pred  J/1k rows
  original                0.968     94%    100%          0.7    1.381     0.6596
  adversarial training    0.968     94%     68%         3.29    1.859     0.7539
  without mouse_events    0.968     94%    100%         2.04    1.907     0.7486
  original: evaded at budget 1 = 64%, 5 = 100%, 10 = 100%
  adversarial training: evaded at budget 1 = 10%, 5 = 57%, 10 = 68%
  without mouse_events: evaded at budget 1 = 7%, 5 = 100%, 10 = 100%

(The built-in demo: a synthetic bot-detection dataset in which the model leans on signals that are cheap to fake. Same accuracy, very different robustness.)

Why

Fraud and bot models are tested on accuracy. Attackers do not care about accuracy: they care about what it costs to get a fraudulent order or a scraping bot through. In the demo, a model with 0.97 AUC lets 64% of bots through when each bot spends one unit of effort, mostly by faking a few mouse events.

Tree ensembles are known to be easy to evade: Kantchelian, Tygar and Joseph (ICML 2016) found boosted trees more brittle than the other model families they tested, and showed that retraining on evading examples ("adversarial boosting") makes them much harder to evade. In tabular data, what matters is the attacker's cost, not how "close" the fake input is to a real one (Kireev, Kulynych and Troncoso, NDSS 2023). This tool is built around that.

Describe the attacker

A JSON file lists the features the attacker controls and what changing them costs (examples/bot-constraints.json):

{
  "budget": 10,
  "features": {
    "requests_per_min": {"min": 0, "direction": "decrease", "cost": 0.05},
    "mouse_events": {"min": 0, "direction": "increase", "integer": true, "cost": 0.05},
    "distinct_ips_24h": {"min": 1, "direction": "decrease", "integer": true, "cost": 3},
    "account_age_days": {"mutable": false}
  }
}
Field Meaning
mutable Whether the attacker can change it. Features you list are mutable unless you say false; unlisted features are fixed (or set "default_mutable": true).
min, max Allowed range
max_change, max_change_rel Largest change, absolute or as a share of the current value
direction increase, decrease or both (a bot can slow down but cannot make its account older)
integer Whole numbers only
cost Attacker cost per unit of change; budget caps the total

Costs are in any unit you choose: dollars, minutes of effort, or a simple 1-to-10 scale. Agree them with the people who see the attacks.

The attack

For each row the model flags, a greedy search changes one attacker-controlled feature at a time, picking the change that lowers the score most per unit of cost, until the row falls under the threshold or the budget runs out. For tree models the only values it tries are just either side of the model's own split points, read from the model (XGBoost, LightGBM, scikit-learn trees, forests and HistGradientBoosting), because nothing in between can change a tree ensemble's output. That makes the search fast and precise; on a one-split model it finds the exact minimum cost (tested). For other models, a grid of data values is used.

The results are lower bounds: a greedy search can miss a cheaper path, so a determined attacker may do better. Exact methods for tree ensembles (mixed-integer programming, Kantchelian et al. 2016) or verification (Chen et al., NeurIPS 2019) are stronger and much slower.

You get the evasion rate at each budget, the median cost to evade, which features attackers would change, and examples.

Harden and measure the cost

tabular-model-robustness harden --model bot_model.joblib --train train.csv --test test.csv --label is_bot --constraints bot-constraints.json --budgets 1,5,10
  • Adversarial training: attack training positives under the same constraints, add the evading versions with their true label, retrain, repeat (--rounds).
  • Dropping cheap features: retrain without the features attacks used most (--drop to choose). In the demo this only moved the attack to other cheap signals: when everything the model relies on is cheap to fake, it needs signals that are costly to fake, such as account age, payment history or verified identity.

Each version is scored on held-out data (AUC, recall and false-positive rate at the threshold), attacked again, and benchmarked with greeninfer for single-prediction latency and energy per 1,000 rows. Robustness that doubles inference cost may not be worth it on a busy checkout; the table makes that visible. The quick benchmark in harden is noisy on shared machines; for published numbers, benchmark the final models with greeninfer and several repeats.

From Python

from tabular_robustness import Constraints, evaluate, compare
cons = Constraints.load("constraints.json", feature_names)
report = evaluate(model, X_test[y_test == 1], cons, budgets=[1, 5, 10])
print(report["evasion_rate"], report["median_cost"], report["features_used"])

Responsible use

Test models you own or are allowed to test. The output shows where your own model is weak so you can fix it; the constraint file describes what an attacker can do, which you should treat as sensitive.

SDG alignment

This tool supports SDG target 9.1 (reliable, resilient infrastructure): fraud and bot defences that hold up under realistic attacks keep online stores and payment systems trustworthy. It also supports target 9.5 (enhance scientific research): it measures robustness and inference energy together, a combination rarely reported in studies of defended tree models.

Sources

  • Kantchelian A., Tygar J. D., Joseph A. D. (2016). Evasion and Hardening of Tree Ensemble Classifiers. ICML. arXiv:1509.07892
  • Kireev K., Kulynych B., Troncoso C. (2023). Adversarial Robustness for Tabular Data through Cost and Utility Awareness. NDSS. arXiv:2208.13058
  • Chen H., Zhang H., Si S., Li Y., Boning D., Hsieh C.-J. (2019). Robustness Verification of Tree-based Models. NeurIPS.

About

Built by Ahmad Zia, an AI and e-commerce consultant and researcher in efficient and secure inference for gradient-boosted tree models. MIT licensed.

Guide, help and author

Built by Ahmad Zia (Muhammad Ahmad Zia), an AI consultant for ecommerce since 2020 and green AI researcher at the University of Lahore. Research · Google Scholar · ORCID · LinkedIn · GitHub

More AI and store security tools

  • shopbot-shield: Prompt injection protection for ecommerce chatbots and AI shopping assistants
  • model-file-guard: Scan pickle, PyTorch, joblib and other ML model files for hidden code before you load them
  • llm-store-review: Security review of AI chatbots and agents in your code, mapped to the OWASP LLM Top 10 2026
  • rag-content-guard: Find hidden instructions and poisoned documents before they reach your RAG index or AI agent
  • storeguard: Free security scanner for vibe-coded online stores

All 30 tools and agent skills: github.com/MuhammadAhmadZia · ahmadzia.com/tools

Metadata

Release files for tabular-model-robustness 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tabular-model-robustness 0.1.0
File Size Uploaded Provenance Actions
tabular_model_robustness-0.1.0.tar.gz 21.4 kB With provenance Details for tabular_model_robustness-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for tabular-model-robustness 0.1.0
File Interpreter ABI Platform Actions
tabular_model_robustness-0.1.0-py3-none-any.whl Python 3 none any Details for tabular_model_robustness-0.1.0-py3-none-any.whl

Total release size: 41.7 kB

Release files / tabular_model_robustness-0.1.0.tar.gz

Download URL tabular_model_robustness-0.1.0.tar.gz
Size 21.4 kB
Tags Source
SHA-256 checksum
How to use checksums
1a188511578e7002cabd8b2b2b950cbb97d4d6b63ca23a7da5f90b21acd666a4
BLAKE2b-256 checksum
How to use checksums
b97ca22c3f01b6096e0840f46df95ce71d4233102e3d4928a05e05533231b9f5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 5, 2026.

Transparency log

Release files / tabular_model_robustness-0.1.0-py3-none-any.whl

Download URL tabular_model_robustness-0.1.0-py3-none-any.whl
Size 20.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cd941c010d85f1b4ec06c17c3fa587b6e23ec69a1e10fbd1af6fcc07941d3dc6
BLAKE2b-256 checksum
How to use checksums
07e7fba1f91ead8fa8dd61a6dd7b31707d797d0b1aa42cf472b242fbc50338d6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 5, 2026.

Transparency log

Security for tabular-model-robustness 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for tabular_model_robustness-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 5, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page