Skip to content
← All articles

My WhatsApp bot lets the model propose. The code decides.

By Muhammad Umer Khan · Built Sep 2026 to now
Published

I built a WhatsApp bot that runs in production for a travel agency, and by November 2026 it had passed about 2,000 confirmed leads to the team. Customers write in Roman Urdu, Urdu, English or Arabic, leave out dates, correct themselves and ask about several cities in one thread. The obvious design is to hand the chat to a model and save what comes back. I didn't, because the first time the model drops a field, the customer's request is gone. In my bot the model only proposes a change, and plain code decides whether it happens.

The failure you are designing against

A language model is good at reading a message like "do kamray chahiye, 12 se 15 tak". It is less reliable at carrying everything it was told three messages ago. Ask it to return the whole lead every time, and eventually it returns the lead without the hotel the customer named earlier. Save that, and you have lost data nobody will notice until the team sends the wrong quote.

The model returns a patch, not a lead

On each message, the model returns only what that message added or changed, as a typed patch through structured outputs. Every field starts empty, and the schema is strict, so an unknown field is rejected instead of quietly accepted.

class LeadPatch(BaseModel):
    model_config = ConfigDict(extra="forbid", strict=True)
    city: str | None = None
    check_in: DateParts | None = None
    rooms: int | None = None

Empty means nothing was said, never erase it

The merge is plain Python. A field changes only when the patch carries a value for it, so an empty field can never erase what the customer said earlier. That changes what a bad extraction can do: the worst case is a detail missed, and the bot simply asks for it.

The same thinking handles several stays in one enquiry. A different place never overwrites another stay's city. It opens a new stay, and each message is routed to the stay it is about.

Confirmation is a gate, not a courtesy

Nothing reaches the team until the customer confirms the whole requirement, and a correction always gets a fresh confirmation. An exact yes takes a fast path with no model call at all. Anything more natural goes to the model, and a negative or a bit of bargaining doesn't count as yes. Each of those rules has a test.

Most of the work is deciding what to ignore

I expected the hard part to be reading messy enquiries. Much of the real work turned out to be the messages that aren't enquiries at all: vendor quotes, support messages, negotiation between team members, and people replying to the bot's own daily summary. Each one would otherwise have opened a false lead, and each one needed its own rule and its own test.

When to use this pattern

Use it whenever a model's output becomes a record someone trusts: a lead, an order, a booking. Skip it when a wrong answer costs nothing. It costs you more code than a single prompt, and in return the system fails in ways you chose.

More than 230 tests now sit around this bot, covering the webhook, corrections, confirmation, dates, multi-city stays and model failures. That is what makes it safe to keep changing.

I build these for startups. WhatsApp AI chatbots

Free 30-minute build audit

Get in touch to start building yours.

Bring the idea or the workflow. In 30 minutes you get what I would build first and how I would prove it works. NDA before the first call.

calls 2pm to 11pm PKT · reply within 24h · WhatsApp +92 343 2187868