Get One Clean Draft Back

extracting and cleaning the reply text

Part of: Smart Reply Generator

You sent the request; now the model sends something back. The smallest working version of this product has to pull one clean draft string out of that response, ready to drop into an email box. This lesson is that step. Where the text actually lives The Messages API does not return a bare string. It returns a response object whose text sits inside a content list: resp.content is a list of content blocks. For a plain text reply you want content[0].text. That is the raw draft. Raw is not the same as clean Even when you say "return only the reply," models sometimes lead with a throat-clear: "Sure, here's a reply:" on its own line, then the actual draft. Paste that straight into an email and you have shipped the model's stage directions. The smallest useful fix is a tiny cleaner that drops a leading preamble line. One heuristic works well: if the first line ends with a colon, it is almost always a preamble ("Here's a draft:", "Sure, here you go:"). Strip it and keep the rest. Why bother this early You might want to skip cleaning until the harden lessons. But a draft with a preamble line looks fine in a print statement and breaks the moment a real user copies it. Parsing the reply into e

Challenge: Strip the Preamble