DEV Community

Cover image for Your AI support bot needs a handoff policy before it needs a better model
Sushil Barwal
Sushil Barwal

Posted on

Your AI support bot needs a handoff policy before it needs a better model

Most AI support chatbots that disappoint customers don't fail because the model is weak. They fail because nobody decided when the bot should stop talking and hand the conversation to a person. The bot keeps guessing, the customer keeps rephrasing, and by the time a human sees the thread the customer is angry.

Whether you switch on Intercom Fin, Tidio Lyro or build a custom bot, you need the same thing: a small, explicit handoff policy that you can test. This post shows one in about 60 lines of Python, plus the test cases we run against it.

What should trigger a handoff?

In practice, five signals cover most cases:

  1. The customer asks for a human. "agent", "real person", "speak to someone". Never argue with this.
  2. Low retrieval confidence. If your RAG search returns nothing above a similarity threshold, the bot is about to make something up.
  3. Sensitive intent. Refunds above a limit, cancellations, complaints, legal threats, anything about health or safety.
  4. Repeated failure. The customer has rephrased the same question twice, or said "that's not what I asked".
  5. Account actions the bot isn't allowed to do. Changing an address after dispatch, editing a subscription, anything you haven't built and tested as a tool.

Vendors handle some of these for you. Intercom, for example, says it doesn't charge for a Fin outcome when the customer asks for a human, which tells you how central that rule is. With a custom bot you write them yourself, which is a good thing: you can see and test them.

A minimal handoff router

import re
from dataclasses import dataclass, field

HUMAN_PATTERNS = re.compile(
    r"\b(human|agent|real person|someone real|speak to (a|an)? ?(person|someone)|call me)\b", re.I)
SENSITIVE_PATTERNS = re.compile(
    r"\b(refund|chargeback|cancel|complaint|lawyer|legal|injur|unsafe|allergic)\b", re.I)
FRUSTRATION_PATTERNS = re.compile(
    r"(not what i asked|that's wrong|you're not helping|useless)", re.I)

@dataclass
class Turn:
    text: str
    retrieval_score: float  # best similarity score from your search, 0..1

@dataclass
class Decision:
    handoff: bool
    reason: str = ""
    tags: list = field(default_factory=list)

def decide(history: list[Turn], min_score: float = 0.55) -> Decision:
    last = history[-1]
    if HUMAN_PATTERNS.search(last.text):
        return Decision(True, "customer asked for a person", ["requested"])
    if SENSITIVE_PATTERNS.search(last.text):
        return Decision(True, "sensitive topic", ["sensitive"])
    if FRUSTRATION_PATTERNS.search(last.text):
        return Decision(True, "customer frustrated", ["frustration"])
    if last.retrieval_score < min_score:
        return Decision(True, f"low retrieval score {last.retrieval_score:.2f}", ["no-source"])
    low_recent = [t for t in history[-3:] if t.retrieval_score < min_score + 0.1]
    if len(low_recent) >= 2:
        return Decision(True, "two weak answers in a row", ["repeat"])
    return Decision(False)

if __name__ == "__main__":
    cases = [
        ([Turn("Where is my order?", 0.82)], False),
        ([Turn("Can I talk to a real person?", 0.90)], True),
        ([Turn("I want a refund for order 1042", 0.88)], True),
        ([Turn("Do you ship to Perth?", 0.31)], True),
        ([Turn("What sizes do you stock?", 0.60), Turn("I mean for kids", 0.62)], True),
        ([Turn("That's not what I asked", 0.75)], True),
    ]
    for history, expected in cases:
        d = decide(history)
        status = "ok" if d.handoff == expected else "FAIL"
        print(f"{status:4} handoff={d.handoff!s:5} {d.reason or '-'} | {history[-1].text}")
Enter fullscreen mode Exit fullscreen mode

Running it prints:

ok   handoff=False - | Where is my order?
ok   handoff=True  customer asked for a person | Can I talk to a real person?
ok   handoff=True  sensitive topic | I want a refund for order 1042
ok   handoff=True  low retrieval score 0.31 | Do you ship to Perth?
ok   handoff=True  two weak answers in a row | I mean for kids
ok   handoff=True  customer frustrated | That's not what I asked
Enter fullscreen mode Exit fullscreen mode

Regex is deliberately boring here. You can swap it for a small classifier later, but start with rules you can read in a code review, and keep the test cases.

What goes to the human?

A handoff is only useful if the agent doesn't have to ask everything again. Send:

  • the full transcript,
  • the reason and tags from decide(),
  • the sources the bot looked at (document IDs and scores),
  • customer identifiers you're allowed to share (order number, email),
  • the customer's language and time zone.

Post it into the helpdesk your team already uses (Intercom, Zendesk, Freshdesk, HubSpot) rather than a new inbox. Tell the customer what happens next and roughly when: "A person from our team will reply here within two business hours."

How do you tune the threshold?

Take 100–200 real questions from your inbox. Label each one "bot should answer" or "should go to a person". Run your retrieval on all of them and record the best score. Then pick the min_score that keeps wrong answers rare, even if it hands off a bit more often. Early on, a bot that hands off 40% of conversations and is right on the other 60% builds more trust than one that answers 90% and is wrong on a fifth of them.

Re-run the same set after every prompt, model or content change. If the pass rate drops, don't ship.

Tool or custom: does this change?

No. If you use Intercom Fin or Tidio Lyro, write these rules down and check that the tool's settings match them. If you build custom, the router above is a starting point. We compare the two routes, with current vendor pricing, in a separate guide.

If you need a custom bot wired into your own order, booking or CRM systems, our AI chatbot development team at Dzimark builds them for businesses in the USA, UK, Canada and Australia.

FAQ

Should the bot ever refuse to hand off?
No. If a customer asks for a person, route them. You can offer one more self-service option first, but never block it.

What similarity threshold should I use?
It depends on your embedding model and content. Calibrate it on your own labelled questions instead of copying a number.

Does handoff hurt automation rates?
Slightly, at first. It also stops the confident wrong answers that cause refunds and complaints, which cost more.

Where should I log handoff reasons?
Alongside the transcript, so you can count them weekly. The top reasons tell you which help articles or tools to build next.

Top comments (0)