I8 · Natural Language Processing in Practice

Intent-Based Chatbots

An intent-based chatbot classifies each user message into one of a fixed set of intents, such as check_balance or block_card, extracts entities or "slots" needed to complete the request, such as an account type or a date, and then follows a dialogue flow that asks for missing information, calls a back-end system and replies from templates. Frameworks such as Rasa, Google Dialogflow and Microsoft Bot Framework provide these parts. Many modern assistants combine intent detection for critical actions with a large language model for open-ended questions.

15 min Intermediate · Sublevel Advanced Jump to the activity

What you need: The earlier topics of this module.

Definition

Bank chatbots answer "mera balance kitna hai?", "block my card" and "loan ka interest rate?" thousands of times a day, reliably and without inventing anything. Most of them do not generate free text at all; they recognise what you want and run a fixed, tested response.

An intent-based chatbot classifies each user message into one of a fixed set of intents, such as check_balance or block_card, extracts entities or "slots" needed to complete the request, such as an account type or a date, and then follows a dialogue flow that asks for missing information, calls a back-end system and replies from templates. Frameworks such as Rasa, Google Dialogflow and Microsoft Bot Framework provide these parts. Many modern assistants combine intent detection for critical actions with a large language model for open-ended questions.

In simple words

A good receptionist first works out why you came (the intent), notes the key details such as your name and appointment time (the slots), asks for anything missing, and then follows the right procedure. An intent-based bot does exactly that.

Overview

  • An intent-based chatbot works out what the user wants (the intent) and the details (entities or slots), then responds.
  • Intents such as check_balance or book_ticket are learned from example phrases.
  • Slot filling asks follow-up questions until all required details are known.
  • Dialogue management decides the next step based on the conversation so far.
  • A fallback hands over to a person when confidence is low.
  • Frameworks include Rasa and Google Dialogflow; LLMs now add flexible understanding.

Why it matters

Banks, telecom companies, railways and government services use intent bots because they are predictable, auditable and safe for actions involving money or personal data. Building one teaches classification, entity extraction and conversation design together.

Key terms

Intent
The goal behind a message, such as book_ticket or cancel_order.
Utterance
One example message a user might send for an intent.
Slot
A piece of information the bot needs, such as date, city or amount.
Slot filling
Asking follow-up questions until all required slots are known.
Fallback
What the bot does when it is not confident: rephrase, offer options or hand over to a human.
Dialogue state
What the bot currently knows about the conversation.

Types

Intent-based chatbots are built from several types of component. Each handles one part of the conversation.

1. Intent classification

Deciding which goal a message expresses.

  • How it works: A text classifier trained on example phrases per intent outputs the most likely intent and its confidence.
  • Example: "How much money is in my account?" classified as check_balance with confidence 0.94.
  • When to use it: Use it as the first step; add many varied examples per intent, including Hinglish.

2. Entity extraction and slot filling

Finding details in the message and asking for missing ones.

  • How it works: NER or pattern rules extract values such as dates and cities into slots; the bot asks a question for each empty required slot.
  • Example: For "Book a train to Jaipur", the bot fills destination = Jaipur and asks "For which date?".
  • When to use it: Use it for task-oriented bots such as bookings, orders and complaints.

3. Dialogue management

Keeping track of the conversation and choosing the next action.

  • How it works: Rule-based flows or state machines define steps; learned policies choose actions from the dialogue state.
  • Example: After all slots are filled, the bot confirms the booking and calls the railway API.
  • When to use it: Use it to handle multi-turn conversations reliably.

4. Response generation

Producing the bot's reply.

  • How it works: Template responses fill slot values into fixed text; retrieval picks a stored answer; generative models write new text.
  • Example: "Your ticket to Jaipur on 12 March is confirmed. PNR: …"
  • When to use it: Use templates where accuracy matters, such as payments, and generation for open chat.

5. Fallback, escalation and evaluation

Handling messages the bot cannot understand and measuring how well it works.

  • How it works: Below a confidence threshold the bot asks for clarification or hands over to a person; metrics include intent accuracy, task completion rate and user satisfaction.
  • Example: Escalating to a human agent after two failed attempts.
  • When to use it: Use them to keep users from getting stuck and to improve the bot over time.

Explained in detail

How the parts fit together

For each intent, designers write example utterances, often 20 to 100 per intent, covering different phrasings, languages and spellings: "block my card", "card band karo", "I lost my debit card". An intent classifier, from TF-IDF and logistic regression to a fine-tuned transformer, learns to map new messages to intents. An entity extractor finds slots, using patterns for things like dates and amounts and trained models for names and places. A dialogue manager keeps the state: if the intent is book_ticket and the destination slot is empty, it asks "Where do you want to go?" When all slots are filled, the bot confirms, calls the booking system through an API and replies with a template that inserts the real details.

MessageIntentSlotsBot action
"Mumbai se Pune kal ka ticket"book_ticketfrom=Mumbai, to=Pune, date=tomorrowAsk for class of travel
"block my card please"block_cardcard=debit? (unknown)Ask which card, then verify identity
"what's the weather"out_of_scopenonePolitely say what the bot can help with

Designing good conversations

  • Always include an out-of-scope intent and a clear fallback, so unknown questions do not trigger wrong actions.
  • Confirm before any irreversible action, such as transferring money or cancelling a booking.
  • Offer an easy way to reach a human, and pass on the conversation so far.
  • Support the languages and scripts your users actually type, including Hinglish in Roman script.
  • Log real conversations (with consent and privacy safeguards) to find new intents and failing phrasings.

Intent bots and large language models

Large language models can chat about almost anything, but they may invent facts or take unexpected actions. Intent bots are narrow but predictable. Many production systems now combine them: an intent classifier decides whether a message needs a tested action, such as checking a balance, which runs through the fixed flow, while general questions are answered by an LLM grounded in the organisation's documents. Some systems even use the LLM to recognise intents and fill slots, while keeping the actions themselves in controlled code.

Measure a bot with real conversations: the share resolved without a human, the share handed over, how often intents are misrecognised, and user satisfaction. A rising hand-over rate on one topic usually reveals a missing intent.

How it works

  1. List the tasks users most need and turn each into an intent.
  2. Write varied example utterances for each intent, in the users' languages.
  3. Define slots and the questions that fill them.
  4. Train the intent classifier with an out-of-scope class and a confidence threshold.
  5. Test with real users, review failed conversations and add examples regularly.

In code

intent_bot.py
import re
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.linear_model import LogisticRegression
from sklearn.pipeline import make_pipeline

examples = {
    "check_balance": ["what is my balance", "mera balance kitna hai", "show account balance", "balance batao"],
    "block_card": ["block my card", "card band karo", "i lost my debit card", "my card was stolen"],
    "book_ticket": ["book a ticket to pune", "mumbai se delhi ticket chahiye", "train ticket for tomorrow", "ticket book karo"],
    "out_of_scope": ["tell me a joke", "who won the match", "what is the weather", "sing a song"],
}
X = [u for us in examples.values() for u in us]
y = [i for i, us in examples.items() for _ in us]
clf = make_pipeline(TfidfVectorizer(analyzer="char_wb", ngram_range=(2, 4)), LogisticRegression(max_iter=2000)).fit(X, y)

CITIES = {"pune", "mumbai", "delhi", "chennai"}
def reply(message):
    probs = clf.predict_proba([message.lower()])[0]
    intent, conf = clf.classes_[probs.argmax()], probs.max()
    if conf < 0.33 or intent == "out_of_scope":
        return f"[{intent} {conf:.2f}] Sorry, I can help with balance, cards and tickets."
    if intent == "book_ticket":
        city = next((w for w in re.findall(r"[a-z]+", message.lower()) if w in CITIES), None)
        return f"[{intent} {conf:.2f}] " + (f"Booking to {city.title()}. Which date?" if city else "Where do you want to go?")
    if intent == "block_card":
        return f"[{intent} {conf:.2f}] Please confirm the last 4 digits of the card to block."
    return f"[{intent} {conf:.2f}] Your balance is shown after OTP verification."

for m in ["Card kho gaya, block kar do", "chennai ka ticket", "kitna paisa hai account mein", "play some music"]:
    print(f"{m:<30} -> {reply(m)}")

Output

Card kho gaya, block kar do    -> [block_card 0.46] Please confirm the last 4 digits of the card to block.
chennai ka ticket              -> [book_ticket 0.44] Booking to Chennai. Which date?
kitna paisa hai account mein   -> [check_balance 0.35] Your balance is shown after OTP verification.
play some music                -> [out_of_scope 0.30] Sorry, I can help with balance, cards and tickets.

Try it yourself

How an intent bot handles a message

Put the steps in order.

  1. 1Ask for any missing slot
  2. 2Reply using a template with the real details
  3. 3Classify the intent and check confidence
  4. 4Extract slots such as city and date
  5. 5Receive the user's message
  6. 6Confirm and call the back-end system

Intent bot or LLM?

Which suits each request better?

  • Explain the difference between savings and current accounts

  • Summarise the new loan policy document

  • Transfer ₹5,000 to my brother

  • Block my credit card

Common mistakes

  • Leaving out an out-of-scope intent, so every message triggers some action.
  • Writing example utterances only in formal English.
  • Making it hard to reach a human.

Check yourself

Question 1

1. In "book a ticket to Pune tomorrow", what are "Pune" and "tomorrow"?

Question 2

2. Why are intent bots preferred for money transfers?

Question 3

3. What should the bot do when confidence is low?

Summary

  • Intent bots classify messages into intents, fill slots and follow fixed dialogue flows.
  • They are predictable and safe for critical actions; include out-of-scope handling and human hand-over.
  • Modern assistants often combine intent flows for actions with LLMs for open questions.

Finished reading?

Sources: Rasa documentation: intents, entities and stories · Jurafsky and Martin, Speech and Language Processing (3rd ed. draft)