Surviving Bad Input and Flaky Networks
errors, retries, and cost caps
Part of: Persona Chatbot
Your bot works on your machine, on your inputs, with your Wi-Fi. A real bot faces empty messages, network blips, and a cost ceiling it must not blow through. This lesson is the unglamorous armor that turns a demo into a tool. Three things that will go wrong 1. Empty or junk input. The user hits enter on a blank line. Don't append an empty user turn and don't call the API; just reprompt. 2. The network fails. Calls time out or return a transient error. Wrap them and retry a bounded number of times. 3. It costs money. Every call spends tokens. A runaway loop or a giant history can rack up a bill fast, so you cap it. A bounded retry The key word is bounded . You retry, but never forever, otherwise a persistent outage becomes an infinite loop that spends money on every attempt. You get max retries + 1 total attempts. Each attempt costs tokens whether it succeeds or fails, so the retry budget is a cost decision. Exponential backoff (2 attempt) spaces the tries out so you don't hammer a struggling server. Guard the input One if not user text before you touch history saves a whole class of "why did the API 400" bugs. Validate at the boundary, before the request, not after. Cap the cost Be
Challenge: Bounded Retry Budget