Skip to content
Aadil Salman Butt
← All work
Case study 01

My own productBeta

Local AI Anti-Spam

A WordPress plugin that filters contact-form and comment spam with a model I trained in Python and run in plain PHP. No CAPTCHA, no API key, and no message ever leaves the site.

Read the narration
  1. Contact form spam, stopped on your own server.
  2. Small businesses lose real leads to spam filters. CAPTCHAs annoy customers, and cloud filters read every message.
  3. Local AI Anti-Spam holds spam in a quarantine. Nothing is deleted, and one click delivers anything real.
  4. Every decision shows its score and the words behind it.
  5. On a test site, six of six genuine enquiries got through. Six of seven spam messages were held, and the unsure one was delivered with a warning tag.
  6. The model was trained from scratch in Python, and runs inside WordPress in PHP, matching to four decimal places.
  7. Free, private, and open source. Now in beta.
Role
Product, data, model training, PHP plugin and CI
Timeline
Oct 2026 to now
Stack
Python, scikit-learn, PHP, WordPress, MiniLM, GitHub Actions
Scale
Beta 0.1.0, CI on PHP 7.4 to 8.3

The problem

Contact-form spam is now written by cheap language models: fluent, unique enquiries that pass CAPTCHAs, honeypots and keyword rules. The filters that can read them, like Akismet and CleanTalk, send every visitor's message to their own cloud and charge per check.

I wanted a filter that reads the message, runs on ordinary shared hosting, sends nothing off the site and never silently loses a real lead.

What I built

Quarantine list with sender, message, form, score and the words behind each verdict

01

A quarantine instead of a delete button

Spam is held for 30 days, never deleted on arrival. Releasing a message delivers it exactly as it would have been, notification email included, and can add the sender to an allow list. If anything fails, such as a missing model file, the message is delivered.

Why this was held: the model scored the message 1.00, above the 0.97 threshold, with the words that drove it

02

Every verdict explains itself

Each held message shows its score, the threshold it crossed and the words that pushed it towards spam. A site owner can see why something was held before deciding to release it.

Trained in Python, runs in PHP, same score to four decimal places

03

Trained in Python, served in plain PHP

A logistic regression on hashed word and character n-grams plus link and sender features, trained on 96,549 licence-checked rows. A custom featurizer uses crc32 hashing in both languages, and shared fixtures prove PHP and Python agree to four decimal places. PHP reads only the weights a message touches, straight from a 2.1 MB file.

Rules page with always-allow and always-block lists

04

Rules the owner controls

Allow and block lists for emails, domains, IPs and phrases run before the model. If a message matches both lists, allow wins.

How it fits together

Every check runs inside WordPress. The model is trained offline and ships as a file in the plugin.

  1. Form or commentCF7, WPForms, comments
  2. Allow and block listschecked first
  3. Local model in PHP2.1 MB, 3.5 ms worst case
  4. Deliveredunsure ones tagged
  5. Quarantine30 days, one-click release

Decisions and trade-offs

A small linear model instead of a transformer

It has to run on cheap shared hosting with no extensions. A hashed logistic regression scores an 8 KB message in 3.5 ms (p95) with about 8 MB of extra memory, and CI fails the build past 20 ms or 16 MB.

Trade-off: less accuracy than the MiniLM model I also trained. That one is kept for an optional cloud second opinion on unsure messages.

Fail open, hold instead of delete

For a small business, a lost enquiry costs more than one spam email. Unsure messages are delivered with a [Possible spam] tag, errors deliver the message, and held mail waits 30 days.

Trade-off: some spam still reaches the inbox, tagged.

Evaluation that can't flatter itself

Splits are grouped by source and by synthetic template, so test styles are never seen in training, and synthetic text is reweighted so the generator's style can't become a spam signal.

Trade-off: lower headline numbers. They still come from public and synthetic data until real labelled traffic is collected.

Results

0.33%
of genuine messages held on the synthetic test set (95% CI 0.19 to 0.58%)
90.5%
of spam caught at that rate. Not yet measured on real contact-form traffic
3.5 ms
worst-case check in plain PHP (p95, 8 KB message)
Next case studyDentalAI Receptionist