When the Draft Comes Back Broken

validating and repairing model output

Part of: Smart Reply Generator

Your generator works on the happy path. Now make it survive the ugly one. Models occasionally return an empty string, a novel three paragraphs long, or a draft wrapped in "quotation marks" as if quoting itself. A tool that copies those straight into someone's inbox is not finished. This is the hardening lesson. The three failure shapes Almost every bad reply is one of these: 1. Empty or whitespace : the model returned nothing usable. Catch this and fall back; never send a blank reply. 2. Wrapped in quotes : it returned "Sounds good!" with literal quote marks, because it treated the reply as a quotation. Strip the surrounding quotes. 3. Too long : a one-line question got a five-sentence essay. Cap the length so it stays reply-sized. A single cleaner handles all three: Note the order: strip whitespace, then quotes, then whitespace again, since a leading space can hide inside the quotes. None is a deliberate signal that this draft is unusable. The caller can then try the next candidate or a safe default. Fallbacks, not crashes Robustness here means degrading gracefully. If every candidate cleans to None, don't raise. Return a safe generic reply like "Thanks, I'll get back to you." A t

Challenge: Reject or Clean