The Smallest Filter: A Blocklist
keyword blocklist pre-filter
Part of: Guardrails & Moderation Filter
A classifier call costs money and a network round trip. The cheapest filter costs neither: a blocklist is a plain Python collection of terms you never want reaching the model, or leaving it, checked with nothing more than string matching. It's the smallest thing that works, and you could ship it in five minutes. What a blocklist actually is A blocklist is a set of banned words or phrases. Screening text against it is a lookup, not an API call, so it runs instantly and gives the same answer every time. That's why it lands in lesson 2 instead of lesson 5: you get a working first layer of defense before you write a single line that touches the network. The bug every beginner blocklist has Naively checking if term in text matches substrings , not words. A blocklist containing "ass" flags the word "class." A blocklist containing "cum" flags "document." This is the single most common false-positive bug in content filtering, and it erodes trust fast: users hit it on completely innocent text and stop trusting the tool. The fix is whole-word matching : split the text into tokens and compare tokens, not raw substrings. re.findall(r"[a-z0-9']+", ...) pulls out word-like chunks, so "class" is
Challenge: Blocklist Screen