A hybrid chatbot combines an LLM’s flexible conversation with techniques that constrain or ground its replies. Rules alone cannot anticipate every question a student might ask, while an unconstrained LLM can sound convincing when it is wrong. Retrieval-augmented generation (RAG) and rule-based filters are ways to use that conversational flexibility without trusting it unconditionally. section 12.4
A math tutor illustrates the division of work. An LLM can adapt its wording to a student’s questions; the application still needs to handle requirements such as obtaining a parent’s permission before tutoring a child over WhatsApp. LangChain provides a way to experiment with the LLM-backed conversation, but a prompt describing a rule is not the same as an independently enforced rule. section 12.5.2
The prototype builds up the conversational side:
- Connect an LLM through LangChain and put the user’s message into a tutor prompt. section 12.5.2
- Add conversation history so the next reply can depend on earlier turns; specify the parent-permission sequence in the onboarding prompt. section 12.5.2
- Test the replies, especially where a mistaken answer or skipped permission step would matter. Prompt instructions alone do not establish reliable behavior. section 12.5.2
>>> class MathConversation(): ... def __init__(self, llm, prompt_string): ... self.llm = llm ... self.memory = \ ... ConversationBufferMemory( ... memory_key='history', ... ai_prefix='tutor', ... human_prefix="user") ... self.convo_chain = ConversationChain( ... llm=llm, memory=self.memory) ... self.convo_chain.prompt = PromptTemplate( ... input_variables=["history", "input"], ... template=prompt_string) ... ... def answer(self, user_input): ... return self.convo_chain.predict(input=user_input)
The Python wrapper pairs a ConversationChain with conversation memory and a supplied prompt. It prototypes context-aware dialogue; it does not implement RAG or a separate rule-based filter. section 12.5.2
A fluent reply can still be wrong
In a number-sequence quiz, the tutor praises “12” as correct for 2, 4, 6, 8, then says the next number is 10. The contradiction shows why a teaching chatbot should not treat an LLM’s confident response as a checked answer. section 12.5.2
The practical pattern is to let the LLM help with open-ended interaction while grounding or checking what the application cannot afford to get wrong. The LangChain tutor demonstrates the generative component and its limits, not a completed RAG-and-filter system. section 12.4 section 12.5.2

