Tutorials ↗

When a chatbot classifier fails: reproducible closed, open, and recovery states

A downloadable, no-network Python lab injects classifier timeouts, exhausted daily screening budget, and a false positive to compare fail-closed, fail-open, retries, and an exact recovery rule.

Timeout or exhausted screening budget branches into fail closed with no generator call and fail open with an unscreened-generation state

Once a chatbot puts screening in front of generation, the difficult paths are often the failure paths: the classifier does not answer, the daily screening budget is gone, or an ordinary question gets classified as something that must be blocked. A generic error message leaves important facts hidden: whether the generator already ran, how much budget remains, and how a request can recover.

This article narrows that question to a local experiment: one controlled screening stub, one controlled generator stub, and ten fixed run records. It compares fail_closed and fail_open when screening is unavailable, preserves an exact recovery rule after a false positive, and writes classifier calls, retries, budget movement, and generator state into JSON. The downloadable package runs locally and makes no inference-service connection.

Download Classifier Failure Lab v1.0.0. It contains a Python-standard-library runner, the recorded results.json, an English local result viewer, and run instructions.

The original question came from an author’s self-report

The starting point was this Reddit post. Its author reported a parody chatbot using Workers AI with Llama 4 Scout, a generated portion of one to three sentences capped at 130 tokens, and separate daily hard caps for jokes and safety checks. The author described a worst case of about $21/day. Those are statements about that author’s system and capped cost; they are not current model pricing, a cost of this article, or a classification-quality guarantee.

The author also described a regex pass followed by a classifier with its own budget, and withholding a reply when that classifier did not answer. Their question was:

when screening sits in front of something meant to be offensive, do you fail closed and eat the false alarms, or fail open?

The post supplies two useful engineering boundaries: a word-ending matcher repeatedly missed inflected forms, and the site question why are you so mean? was falsely read as a disclosure needing protection. I did not rerun that system or decide which content should be classified. I used those two engineering problems to design reproducible states and recovery checks.

Statement in the sourceWhat the local lab actually doesWhat remains unknown
The classifier has its own daily budget and an unanswered call withholds a reply.It uses an integer budget and scripted timeout outcomes to expose the call boundary.A real classifier’s latency, limits, and quality.
The source author used Llama 4 Scout and a 130-token maximum.Its generator returns a fixed LOCAL_STUB_REPLY.Any real-model output or price.
An ordinary site question was falsely blocked.It adds one explicit recovery branch for the complete matching question.Whether other questions deserve a bypass.

Separate unavailable screening from a definite block

fail_open addresses a state where screening cannot make a decision. When the classifier has already returned block, both policies preserve that block and neither one calls the generator. Keeping those cases separate distinguishes a service failure from an explicit screening decision.

The local script injects three outcomes: allow, block, and timeout. Every classifier call consumes one local budget unit, and a timeout gets at most one retry. fail_closed returns temporary_unavailable and records the request trace. fail_open calls the stub and records generated_without_screening, making that risk path visible in the result file.

For the false positive, the example does not change every block into an allow. It matches one reviewed whole message, Why are you so mean?, before calling the classifier. A near match, Why are you so mean now?, does not bypass the classifier and remains blocked. The matching branch records bypassed_by_exact_recovery_rule and preserves the budget. The recovery condition itself can therefore be reviewed and regression-tested.

English state diagram showing a request through an exact recovery rule, budget and classifier, then branches for allow, block, timeout, temporary unavailable, unscreened generation, and a recovered follow-up

Figure 1: A definite block, a screening failure, and false-positive recovery have separate states. “Recovery” means a new request has available screening or fresh budget; it does not simulate a real service clock. View full size.

Ten recorded runs expose retries, budget, and generator calls together

Running python3 lab.py --self-test --output results.json on Python 3.9.6 passed seven public-behavior contracts and wrote ten JSON records. Each row is a separate bounded input. budget shows the local screening budget before and after the request.

Injected conditionPolicy or recovery pathClassifier calls / retriesBudgetGeneratorResponse state
Two timeoutsfail_closed2 / 12 → 0notemporary_unavailable
Two timeoutsfail_open2 / 12 → 0yesgenerated_without_screening
Daily budget already exhaustedfail_closed0 / 00 → 0notemporary_unavailable
Daily budget already exhaustedfail_open0 / 00 → 0yesgenerated_without_screening
Ordinary question classified as blockedfail_closed1 / 02 → 1noblocked_by_classifier
Ordinary question classified as blockedfail_open1 / 02 → 1noblocked_by_classifier
Exact recovery rule matchesexact_recovery_rule0 / 02 → 2yesgenerated_after_exact_recovery_rule
Near match to recovery phraseexact_recovery_rule1 / 02 → 1noblocked_by_classifier
New request after a timeout, screening availablefail_closed1 / 01 → 0yesgenerated_after_allow
New request with restored budgetfail_closed1 / 01 → 0yesgenerated_after_allow

The first two pairs show the policy difference. Given the same timeout or zero budget, fail closed keeps the user in an explainable unavailable state while fail open continues and leaves an unscreened-generation marker. The false-positive rows are outside those failure branches: both policies retain blocked_by_classifier. The near-match row proves that the recovery rule checks the complete input. The recovery rows show the other requirement for a generator call: an explicit bypass condition or fresh usable screening.

The actual English local result viewer lists ten records with policy, response state, screening calls, budget movement, and generator-call status

Figure 2: The English viewer reads the results.json from this run. Yellow marks unscreened generation; red marks a definite block or temporary unavailable state; green marks a stub call after allow or exact recovery. View full size.

Re-run the downloadable example

After unzipping the package, Python 3.9 or later is enough:

python3 lab.py --self-test --output results.json
python3 -m http.server 4349 --bind 127.0.0.1

The second command only serves static files from the current directory. Open http://127.0.0.1:4349/viewer.html and the English viewer loads the adjacent results.json. The script installs nothing, makes no network request, reads no credential, and sends no input to an external model.

Its behavior contracts cover visible outcomes: fail closed has no generator call; fail open records unscreened generation; zero budget has no hidden classifier call; a definite block remains blocked; the exact recovery rule spends no budget; and a new request after service or quota recovery returns to the allow path. The tests do not require a particular internal helper, so the implementation can change while preserving the state contract.

Give the user a next step instead of a generic error

For a product that needs a screening decision before it can continue, place temporary_unavailable next to the input and send action. Say that the current request did not reach generation, and provide a retry path. Count that retry in the budget and run record; otherwise one timeout can quietly become several calls.

When a product deliberately chooses fail open, retain generated_without_screening as a queryable state instead of mixing it into an ordinary allow. That gives later review a way to distinguish “the classifier allowed this” from “the system never got a classifier decision.” Keep false-positive repairs narrow as well: begin with an explainable complete pattern, retain the triggering sample and regression record, and expand only when evidence supports it.

For a related local example about visible failures, recovery, and small behavior contracts in a form workflow, see A Minimal Test Strategy for a Small Web Project: Two Real Regressions.

This lab establishes that ten local control-flow records preserve their expected trace. A real classifier’s coverage, accuracy, latency, cost, and user experience still need measurement in the product environment where they matter.

← Back to the list