Off-Topic and Malformed Input

handling off-topic and malformed replies

Part of: FAQ Support Bot

Real users don't ask clean questions. They ask about the weather, paste three questions at once, submit an empty string. Sometimes the model itself replies in a shape you didn't ask for. This lesson hardens the bot against the messy middle: inputs and outputs that aren't wrong exactly, just not what you planned for. Three categories of mess 1. Off-topic input. "What's your favorite movie?" isn't a support question. The keyword check from lesson 3 already scores this near zero against a real FAQ, so it routes to refusal on its own. Worth stating plainly: off-topic and unsupported-but-on-topic get the same treatment, which is refuse. 2. Empty or junk input. A blank question, or one that's only whitespace or punctuation, has no keywords. keywords("") returns an empty set, so every score against it is 0. That's safe by construction, but only if you check for it before doing anything expensive. 3. Malformed model output. The model is supposed to answer in one sentence plus a citation line. Sometimes it won't: it skips the citation, adds commentary, or wraps the answer in markdown. Your citation-parsing code from lesson 5 already treats "no citation found" as a handleable case instead of

Challenge: One Clean Refusal Path