When the Tone Isn't on the Menu
validating input, fallback
Part of: Tone Rewriter
Your rewriter works when you feed it "formal" and a paragraph of text. Now feed it " FORMAL " with trailing spaces, or "sarcastic" which has no preset, or an empty string. A script assumes clean input. A tool defends against messy input, because real users type messily. Two inputs, two failure modes A rewrite request has a tone and a text, and each breaks in its own way. The tone might be mis-cased ("Formal"), padded (" formal "), or unknown ("sarcastic"), and none of those should crash the tool. The text might be empty or whitespace-only, in which case there's nothing to rewrite and calling the API just wastes money on a nonsense reply. Normalize the tone before you look it up Lowercase it and strip the whitespace so " FORMAL " and "formal" hit the same preset. Then, if it's still not a known tone, fall back to a sensible default instead of crashing: Falling back beats erroring here. The user still gets a rewrite, just in the safe default tone, and you can tell them "unknown tone, used neutral." Better to degrade gracefully than to hard-stop. Reject empty text early Empty text is the one case where you should not call the model. Guard it before the request: Catching this early sav
Challenge: Guard the Rewrite Request