Skip to content
elevatedevco

LLMs & Agents

Building your first chatbot

Learn Building your first chatbot: 34 practice questions and answers with an interactive quiz — from the offline AI Learning app.

Intermediate34 questions34 quiz questions

Questions & Answers

Tap a question to reveal its answer. Written for self-study and interview preparation.

What is a chatbot?

A chatbot is a computer program that talks with people using text or voice. It reads what a user types (or says), figures out what they mean, and sends back a reply. Chatbots are used in apps and websites to answer questions, help with tasks, or just chat.

In a rule-based chatbot, what does a 'rule' usually do?

A rule checks the user's message for certain words or patterns and then gives a fixed reply. For example, if the message contains 'hello', the rule replies with a greeting. Rule-based bots are simple because they follow exact instructions written by the programmer.

What is the difference between a rule-based chatbot and an AI (machine-learning) chatbot?

A rule-based chatbot follows exact rules written by a programmer and can only handle situations it was told about. An AI chatbot learns patterns from many examples, so it can handle messages it has never seen before. The AI bot is more flexible, but it needs lots of data to learn from.

What is an 'intent' in a chatbot?

An intent is the goal or purpose behind what a user says. For example, the messages 'What time is it?' and 'Tell me the time' both have the intent of asking for the time. Chatbots try to recognize intents so they can give the right kind of reply.

What is an 'entity' in chatbot language understanding?

An entity is an important piece of information inside a user's message, like a name, date, place, or number. For example, in 'Book a ticket to Delhi for Monday', the entities are 'Delhi' (place) and 'Monday' (day). Bots pull out entities to know the exact details they need to act.

Why do AI chatbots need lots of example conversations to learn?

AI chatbots learn by finding patterns in many examples, so the more examples they see, the better they understand different ways people say things. With few examples, the bot may not recognize new wordings. Lots of varied data helps the bot reply correctly to many kinds of messages.

What does 'training' a chatbot mean?

Training means showing the chatbot many example messages along with the correct responses or labels, so it can learn the patterns. During training, the model adjusts itself to make fewer mistakes on the examples. After training, it can use what it learned to reply to new messages.

In a simple Python chatbot, what does the input() function do?

The input() function pauses the program and waits for the user to type something, then returns that text as a string. A chatbot uses it to read the user's message. The text can then be checked to decide what reply to send.

user_message = input("You: ")
print("Bot:", user_message)
Look at this code. What will the bot reply if the user types 'hi there'? msg = input().lower() if 'hi' in msg: print('Hello!') else: print('Sorry, I did not understand.')

The bot will reply 'Hello!' because the message is changed to lowercase and 'hi' is found inside 'hi there'. The 'in' check looks for 'hi' anywhere in the text, so it matches. If 'hi' were not present, it would print the sorry message instead.

msg = input().lower()
if 'hi' in msg:
    print('Hello!')
else:
    print('Sorry, I did not understand.')
Why is it helpful to convert a user's message to lowercase before checking it?

People type words in different cases, like 'Hello', 'HELLO', or 'hello'. Converting everything to lowercase lets the bot match the word no matter how it was typed. This makes the bot's keyword checks more reliable.

text = "HELLO".lower()  # becomes 'hello'
What is a 'fallback' response in a chatbot?

A fallback response is what the bot says when it does not understand the user's message. Instead of staying silent or crashing, it gives a polite reply like 'Sorry, I did not understand that.' Good fallbacks make the bot feel friendlier and can ask the user to rephrase.

What is a conversation 'loop' in a chatbot program?

A conversation loop is code that keeps asking for the user's input and replying again and again, so the chat continues. Without a loop, the bot would answer only once and then stop. The loop usually runs until the user types something like 'bye' to quit.

while True:
    msg = input("You: ")
    if msg == 'bye':
        break
    print("Bot: I hear you!")
In the loop below, how does the user make the chatbot stop? while True: msg = input('You: ') if msg == 'bye': break print('Bot: Hi!')

The user makes the bot stop by typing 'bye', which makes the if condition true and runs break to leave the loop. Until then, the loop keeps printing 'Bot: Hi!' for every message. The word must match 'bye' exactly for it to stop here.

while True:
    msg = input('You: ')
    if msg == 'bye':
        break
    print('Bot: Hi!')
What is 'natural language' when we talk about chatbots?

Natural language means the everyday human language people use to speak and write, like English or Hindi. Chatbots try to understand natural language instead of forcing users to type special commands. Understanding natural language is hard because people say the same thing in many different ways.

What does NLP (Natural Language Processing) help a chatbot do?

NLP is the field of AI that helps computers understand and work with human language. It lets a chatbot break a sentence into words, find the meaning, and figure out the user's intent. NLP also helps the bot generate replies that sound natural.

What is 'tokenization' in processing a chatbot message?

Tokenization means splitting a sentence into smaller pieces called tokens, usually words. For example, 'I love pizza' becomes the tokens 'I', 'love', and 'pizza'. Breaking text into tokens makes it easier for the computer to analyze each part.

sentence = 'I love pizza'
tokens = sentence.split()  # ['I', 'love', 'pizza']
Why might a chatbot give a wrong or strange answer sometimes?

A chatbot can be wrong if it misunderstands the message, was trained on too few or biased examples, or meets a question it never learned about. AI bots predict likely replies, so they can guess incorrectly. This is why it is smart to double-check important information from a chatbot.

Why should you be careful about sharing personal information with a chatbot?

Personal details like your full name, address, passwords, or phone number could be stored or seen by others, which can be unsafe. A chatbot might keep your messages, and you may not know who can read them. It is safest to avoid sharing private information unless you trust the service and an adult agrees.

What is 'bias' in a chatbot, and why does it matter?

Bias means the chatbot treats some people or ideas unfairly because its training data was unfair or unbalanced. For example, a bot might give better answers about one group than another. Bias matters because it can be unfair or hurtful, so builders should use fair, varied data and test their bots.

Why is it a good idea for a chatbot to tell users it is a bot, not a human?

Telling users it is a bot is honest and respects people's right to know who they are talking to. If users think a bot is human, they might trust it too much or share private things. Being clear about being a bot builds trust and is an important part of ethical design.

What does a dictionary in Python let a simple chatbot do with replies?

A dictionary stores pairs of keys and values, so a chatbot can map a keyword to its reply. For example, the key 'hello' can point to the value 'Hi there!'. The bot can look up the user's word in the dictionary to quickly find the matching response.

replies = {'hello': 'Hi there!', 'bye': 'Goodbye!'}
print(replies.get('hello', 'I do not understand'))
In this code, what does replies.get('hi', 'Sorry') return if 'hi' is not a key? replies = {'hello': 'Hello!'} print(replies.get('hi', 'Sorry'))

It returns 'Sorry' because 'hi' is not a key in the dictionary, so get() uses the default value. The get() method is safe because it does not crash when a key is missing. This is handy for chatbots to provide a fallback reply.

replies = {'hello': 'Hello!'}
print(replies.get('hi', 'Sorry'))
What is a 'keyword' approach to matching user messages?

In a keyword approach, the bot looks for certain important words in the user's message to decide the reply. For example, seeing the word 'weather' might trigger a weather answer. It is simple to build but can fail if the user uses different words for the same idea.

Why can keyword matching alone make a chatbot seem 'dumb' sometimes?

Keyword matching only looks for exact words, so it misses messages that mean the same thing using different words. It also cannot understand context, like the difference between 'I am not happy' and 'I am happy' if it only spots 'happy'. This is why smarter bots use machine learning to understand meaning.

What is 'context' in a conversation, and why is it useful for a chatbot?

Context means remembering what was said earlier in the conversation so replies make sense together. For example, if you ask 'What about tomorrow?' the bot needs the earlier topic to answer well. Keeping context helps the bot have a natural, connected chat instead of treating each message alone.

How can adding random variety to replies make a chatbot feel more natural?

If a bot always says the exact same sentence, it sounds robotic and repetitive. By choosing randomly from several greetings like 'Hi!', 'Hello!', or 'Hey there!', the bot feels more lively and human. Python's random.choice() can pick one reply from a list.

import random
greetings = ['Hi!', 'Hello!', 'Hey there!']
print(random.choice(greetings))
What is a chatbot 'response' (or 'utterance')?

A response is the message the chatbot sends back to the user. It can be a fixed sentence, a randomly chosen one, or text the AI generates. Good responses are clear, polite, and actually answer what the user asked.

Why is testing a chatbot with many different messages important?

Testing with many messages shows where the bot fails to understand or gives wrong replies. By trying different wordings, spelling mistakes, and tricky questions, you find problems before real users do. Fixing these issues makes the chatbot more reliable and helpful.

What are 'training examples' (sample messages) for an intent?

Training examples are different sentences that all mean the same intent, used to teach the bot to recognize it. For a 'greeting' intent, examples might be 'hello', 'hi there', and 'good morning'. Giving many varied examples helps the bot recognize the intent even when users phrase it in new ways.

What is a voice chatbot, and how does it differ from a text chatbot?

A voice chatbot listens to spoken words and replies with speech, like a smart speaker. It needs speech recognition to turn your voice into text and text-to-speech to talk back. A text chatbot only reads and writes text, so it does not need those extra speech parts.

What is the role of the print() function in a basic Python chatbot?

The print() function shows the chatbot's reply on the screen so the user can read it. Whenever the bot decides what to say, it uses print() to display that text. It is the main way a simple text chatbot communicates its responses.

print("Bot: How can I help you today?")
Why should a chatbot avoid pretending to be a doctor or giving serious medical advice?

A chatbot is not a trained doctor and might give wrong or unsafe health advice, which could harm someone. For serious problems, people should talk to a real qualified person like a doctor or a trusted adult. A responsible bot should suggest getting real help instead of pretending to be an expert.

What is a large language model (LLM), and how do modern chatbots use it?

A large language model is an AI trained on huge amounts of text so it can predict and generate human-like writing. Modern chatbots use an LLM to understand a message and create a fresh reply instead of picking from fixed sentences. This lets them handle many topics, though they can still make mistakes.

What are the basic steps to build a very simple chatbot?

First, decide what your bot should do and the kinds of messages it will handle. Next, write code to read the user's input, decide a reply (using rules, a dictionary, or AI), and print the response, usually inside a loop. Finally, test it with many messages and improve the replies where it fails.

Put it into practice with AI Learning

This topic — and hundreds more — comes from our free, offline AI Learning app. Practice Q&A, quizzes and cheat sheets anywhere, no account needed.

  • Free
  • No account
  • Works offline
Coming soon toGoogle Play