Language detection fails on real input
We first used tinyld, a fast, free Node.js language-detection library with no API calls. It handled clean single-language text but failed on other input.
"Merhabalar" (a common Turkish greeting with a softening suffix) was classified as Portuguese. Mixed-language messages confused it completely. Short messages of one or two words failed unpredictably.
We replaced the library with a Haiku classifier: a small system prompt and one API call returning a language code. Classification costs are negligible and accuracy is substantially better. The model understands slang, suffixes and mixed-language context that the statistical n-gram detector misses.
For real multilingual customer messages, a small LLM classifier is more reliable than a statistical library. The extra 200-400ms reduces misclassification.
Keep pricing in code
Early versions kept prices in the system prompt. The model invented numbers in perhaps 2-3% of conversations. That meant 2-3% could leave customers with screenshots of nonexistent prices.
We removed prices from the prompt. A deterministic function queries the WordPress plugin’s live price list via REST API. The bot receives exact, current numbers from the function, leaving no pricing information to hallucinate.
Lesson: any value that needs to be exact (prices, dates, counts, availability) should come from a deterministic function. Don't ask the model to remember numbers from the prompt.
Prices can look correct for the wrong location
This failure is especially serious because the quote looks correct.
Location determines the activity package and its price, so the bot must confirm it before quoting. A confused conversation, distracted user or loosely followed prompt can cause it to skip that step and quote an inapplicable price.
We documented this internally as BUG24. The root cause: the bot followed the instruction 'give prices when asked' while missing the guard condition 'only after confirming location.'
The fix: a validation layer that runs after every AI response. If the response contains a price (detected by the € symbol) and the session has no confirmed location, the response is discarded and the model is re-prompted with an explicit instruction to ask for location first. The customer never sees the bad response.
Lesson: for high-stakes output (a price, a booking confirmation, a date) add a deterministic validation layer after the model response. Don't rely on the prompt instruction alone.
Memory disappears at 20 messages
We set MAX_HISTORY=20 to reduce context costs. Customers who asked questions over several days could return to book after the bot had lost the earlier conversation.
We removed the hard limit and added Claude’s prompt caching for long system prompts. This preserves the full conversation while caching the expensive system prompt to keep context costs manageable.
Lesson: don't implement arbitrary message limits. Use prompt caching and token counting to manage costs, not conversation truncation.
Truncation removed the requested prices
A validate() function shortened responses beyond 3 paragraphs for WhatsApp readability. An activity explanation with prices took 4 paragraphs. The 4th paragraph contained the prices and was silently removed, leaving the customer without the information requested.
This happened three times before we identified the pattern from customer follow-up messages.
The fix: if the response contains a € symbol, skip the length check entirely.
Lesson: truncation logic is dangerous when content has structure. Always check what you're cutting off, not just whether the output is long.
Failures found in production
There were 24+ documented bugs over 6 months of production, ranging from Cyrillic location names breaking geolookup, to campaigns not applying correctly to multi-unit bookings, to admin notifications going missing when the hosting platform restarted mid-send.
Failures occurred where systems met: AI and data, the bot and admin system, or model interpretation and code assumptions.
Production exposed paths we had not anticipated in testing.
The bot now handles most customer conversations end-to-end, leaving exceptions to the team. Reaching that point took 6 months of testing our assumptions against real use.