Hardening: Errors, Empties, and Cost

robustness and cost

Part of: AI Text Summarizer

Your summarizer works on the article you tested. A tool works on the article you didn't: an empty file, a network blip, a document so long the bill matters. This lesson adds the unglamorous layer that turns a script into something you'd let a stranger run. Guard the input before you spend a cent The cheapest call is the one you never make. Blank or trivially short input needs no model at all: Every early return here is money saved and a crash avoided. Assume the network will flinch Calls time out and rate-limit. Wrap them and retry with a short backoff instead of dying on the first hiccup: Three attempts with growing waits ride out most transient failures. On the last attempt you re-raise, because failing loudly beats returning a silent lie. Watch the bill, especially on retries Every attempt costs tokens, even the failed ones, because you paid to send the input. On a map-reduce over a long document, a few retries per chunk add up fast. A useful habit is to tally what you actually spent: The final successful attempt adds output tokens; every attempt (including the failures) re-bills the input. Sum that across chunks and you know the true cost of a run, not the optimistic one. Fail

Challenge: Tally the Real Bill with Retries