A ten-layer spam defense for a contact form
A walkthrough of how we hardened our own contact form against bots, keyboard-mashers, and the increasingly creative LLM-generated junk hitting agency inboxes.

Our old contact form was getting 40+ spam messages a day. Half were classic bot-fill, a third were LLM hallucinations, and the rest were someone’s cat. Here is how we brought it to zero without adding a captcha.
The ten layers
- Hidden honeypot field (bots love to fill every input).
- Time-gate — reject submissions under 3 seconds.
- Per-IP rate limit — 3 per hour, in-memory token bucket.
- Email format sanity check, server-side, with MX lookup.
- Disposable-domain blocklist (refreshed nightly).
- Character dominance check — flag messages where one char is >35% of the body.
- Run-length check — flag any run of 5+ identical chars.
- Vowel ratio check — real prose sits in a narrow band.
- Word diversity — ratio of unique words to total.
- Cross-field mash — detect when name, email, and body are all the same keyboard smash.
The killer — statistical prose checks
Most spam filtering talks about tokens and phrases. Once an LLM is generating your spam, tokens stop working. But the shape of real writing — the ratio of vowels to consonants, the unique-word ratio, the distribution of character frequencies — is hard to fake by accident.
// src/lib/spam-heuristics.ts
export function looksLikeGibberish(text: string): boolean {
const s = text.toLowerCase().replace(/[^a-z ]/g, "");
if (s.length < 12) return false;
const chars: Record<string, number> = {};
for (const c of s) chars[c] = (chars[c] ?? 0) + 1;
const max = Math.max(...Object.values(chars));
if (max / s.length > 0.35) return true; // char dominance
if (/(.)\1{4,}/.test(s)) return true; // long run
const vowels = (s.match(/[aeiou]/g) ?? []).length;
const ratio = vowels / s.replace(/ /g, "").length;
if (ratio < 0.2 || ratio > 0.6) return true; // vowel band
const words = s.split(/\s+/).filter(Boolean);
const unique = new Set(words).size;
if (words.length > 8 && unique / words.length < 0.4) return true;
return false;
}The result
40 a day down to 0 in the first week. Two false positives in the first month — both from people who wrote one-word messages like “hi”, which we now let through on length alone.
Want this level of polish on your own app?
We turn forms, flows, and follow-ups into things that feel handmade.
See what we build
Short dispatches written jointly by our design + engineering team about how we work and what we care about.
Related posts

Why we shipped this site dark-first
Most agency sites default to light mode and awkwardly bolt on a dark variant. We did it the other way around — and it changed how we pick colors, typography, and motion.

Welcome to the Studio — what this blog is, and what it is not
A short note on why we started writing again, the cadence we are committing to, and the four things you can expect to find here.

How we scope a build in one call
An inside look at the intake call we run with every new client — what we ask, what we deliberately do not ask, and the one-pager we send 24 hours later.
One studio dispatch. Every month.
What we shipped, what we read, and what we argued about. Zero filler, zero affiliates, one-click unsubscribe.