Cache Repeated Answers to Cut LLM Calls in a Small-Business FAQ Bot (Python + SQLite) A Dev.to tutorial by Ujjwal Dubey, who discloses he co-founded the automation agency NxFlowAI, shows how a small business FAQ bot can cache repeated answers in a SQLite table keyed by a SHA-256 hash of the normalized question, cutting redundant LLM calls. The code refreshes entries after MAX_AGE of 7 days (7 * 24 * 3600 seconds) so answers do not go stale, increments a hits counter on each cache hit, and returns a "cache" or "model" label so operators can log what the cache saves. The tutorial warns never to cache answers containing a customer's name, order or account details, and to clear the table whenever prices, hours or policies change. Cache Repeated Answers to Cut LLM Calls in a Small-Business FAQ Bot Python + SQLite Small businesses get the same ten questions all day: opening hours, delivery areas, how to book. Sending each one to a language model is wasted money. A small cache is one of the simplest ways to control AI automation costs for a small business. import hashlib, re, sqlite3, time db = sqlite3.connec t "answers.db" db.execute """CREATE TABLE IF NOT EXISTS cache key TEXT PRIMARY KEY, question TEXT, answer TEXT, created REAL, hits INTEGER DEFAULT 0 """ def normalise q: str - str: q = q.lower q = re.sub r" ^a-z0-9 +", " ", q return " ".join q.split def key q: str - str: return hashlib.sha256 normalise q .encode .hexdigest MAX AGE = 7 24 3600 refresh weekly so answers do not go stale def answer q, call model : k = key q row = db.execute "SELECT answer, created FROM cache WHERE key=?", k, .fetchone if row and time.time - row 1 < MAX AGE: db.execute "UPDATE cache SET hits = hits + 1 WHERE key=?", k, db.commit return row 0 , "cache" a = call model q db.execute "REPLACE INTO cache key, question, answer, created VALUES ?,?,?,? ", k, q, a, time.time db.commit return a, "model" Cache only general questions. Never cache answers that include a customer's name, order or account details. Expire entries when prices, hours or policies change clear the table on any website update . Log cache versus model so you can see what the cache actually saves. Exact matching catches more than you expect once text is normalised. Fuzzy or embedding matching adds complexity; measure first. Why we often prefer small custom pieces like this over packaged bots: why small custom pieces often beat packaged bots. Disclosure: I co-founded NxFlowAI, an automation agency. Key Takeaways - •Never cache answers that include a customer's name, order or account details. - •This story was reported by Dev.to , covering developments in the dev space. - •AI advancements continue to reshape industries — read the full article on Dev.to for complete coverage. 📖 Continue reading the full article: Read Full Article on Dev.to → https://dev.to/ujjwal dubey 9/cache-repeated-answers-to-cut-llm-calls-in-a-small-business-faq-bot-python-sqlite-1oom