Build an ELIZA-Style Chatbot as a Classroom CS Project
Teach pattern matching, regex, and heuristics with an ELIZA-style chatbot project—perfect for middle/high school CS and interactive equation solver tie-ins.
Hook: Turn confusion about AI into a hands-on classroom win
If your students think chatbots are magic, they won’t learn the computational reasoning behind them. Teachers face two linked pain points: students who can’t explain how AI arrives at an answer, and limited classroom projects that actually teach core CS concepts (pattern matching, regular expressions, heuristics) while staying age-appropriate. Building an ELIZA-style chatbot solves both problems. It’s tangible, debuggable, and perfect for middle/high school or intro CS classes. Plus it connects directly to modern topics—AI literacy, safe tool use, and even interactive equation solvers.
The 2026 classroom context: why ELIZA matters now
In late 2025 and early 2026, K–12 AI literacy initiatives accelerated worldwide. Schools are adding AI modules, and educators are trying to teach not just how to use large language models but how AI systems actually work—especially where they fail. A simple, rule-based chatbot like ELIZA (Weizenbaum, 1966) is a perfect laboratory for that conversation: it makes the mechanics visible and encourages a computational thinking mindset.
Recent classroom reports (late 2025) show middle-schoolers who chatted with ELIZA quickly learned the difference between surface-level language tricks and real understanding. The exercise turned misconceptions into research questions.
— EdSurge-inspired classroom observations (2025–2026)
Project overview: what students will build
Goal: In a 3–6 lesson unit, students design and implement a small chatbot that uses pattern matching, regular expressions, and simple natural-language heuristics to carry short conversations. The bot demonstrates how structured rules produce convincing replies, and how limitations lead to breakdowns—an ideal preface to modern NLP discussions.
Learning objectives
- Understand and apply regular expressions to parse text.
- Design pattern-response pairs and simple transformation rules.
- Implement pronoun swapping and context preservation heuristics.
- Analyze bot failures and connect them to modern LLM limitations.
- Optionally: extend the chatbot to recognize simple math requests and call an interactive equation solver.
Why ELIZA-style bots teach core CS skills
The original ELIZA used a small set of scripts and pattern substitution; it wasn't intelligent in the modern sense, but it excelled at creative use of simple operations. That simplicity is pedagogically powerful:
- Patterns made explicit: Students see how a handful of regex rules produce many conversational pathways.
- Debuggable logic: Rule-based systems produce repeatable, inspectable behavior.
- Transfer to math tools: The same parsing and pattern techniques power input normalization for equation solvers.
Tools & setup (age-appropriate choices)
Choose tools to match your class level and infrastructure. For middle-schoolers, use a visual or block-based frontend with a simple regex interface. For high-school and intro CS, use Python 3.x or JavaScript. Below are recommended stacks.
Simple / low-code
- Scratch with text extension or Blockly for teaching logic without syntax barriers.
- Repl.it / Replit classroom templates with a starter script and guided comments.
Recommended for intro CS
- Python 3.x (built-in re module) plus a simple Flask or Streamlit web UI.
- JavaScript (Node.js) with Express and front-end HTML/CSS for live demos.
- Optional: SymPy (Python) for equation solving extensions.
Step-by-step lesson plan (5 classes, adaptable)
Lesson 1 — Motivation and history (45–60 minutes)
- Hook: Show students ELIZA in action (short demo). Ask: “Is this bot thinking?”
- Mini-lecture: Joseph Weizenbaum, 1966; how ELIZA used scripts and pattern substitution.
- Activity: Students list what the bot seems to understand vs. what it doesn’t.
Lesson 2 — Patterns and regular expressions (60 minutes)
- Teach regex basics: anchors, groups, alternatives, optional items.
- Hands-on: students write regexes to match simple sentences (e.g., "I feel sad", "I can't solve this equation").
- Homework: craft 6 pattern-response pairs for the bot.
Lesson 3 — Building the engine (60–90 minutes)
- Show an ELIZA engine skeleton in code. Explain mapping from pattern to template response.
- Students implement pronoun swap and basic memory (store last topic).
- Test with sample conversations and iterate.
Lesson 4 — Extensions and math tie-in (60 minutes)
- Introduce a special rule set for math requests. Example: detect "solve" or "derivative" with regex.
- Option A: Simple algebra solver built from string parsing (e.g., isolate x in ax + b = c).
- Option B: Send parsed math requests to SymPy or an existing interactive equation solver API and return steps.
Lesson 5 — Reflection, testing, and presentation (45–60 minutes)
- Students demonstrate their bots and explain three rules and one failure case.
- Class discussion: how does rule-based chat differ from modern LLMs? What are risks and strengths?
- Assessment: rubric-based check of core competencies.
Core code patterns and examples
Below are small, copy-paste-friendly examples for Python and JavaScript to get students started. Teachers can paste these into repls or starter files.
Python: Minimal ELIZA engine (conceptual)
import re
# Pattern-response list (pattern, list of possible templates)
RULES = [
(r"I need (.*)", ["Why do you need {0}?", "Would getting {0} help you?"]),
(r"I can't (.*)", ["What stops you from {0}?", "Have you tried breaking {0} into smaller steps?"]),
(r"Solve (.*)", ["Let me try to parse that: {0}. Do you want steps or just the answer?"]),
(r"(.*)", ["Tell me more."])
]
def swap_pronouns(fragment):
# Very small pronoun swap map
swaps = {"I": "you", "me": "you", "my": "your", "you": "I"}
words = fragment.split()
return ' '.join(swaps.get(w, w) for w in words)
import random
def respond(text):
for pattern, templates in RULES:
m = re.match(pattern, text, re.IGNORECASE)
if m:
phrase = m.group(1) if m.groups() else ''
phrase = swap_pronouns(phrase)
template = random.choice(templates)
return template.format(phrase)
return "Hmm. Tell me more."
# Example
print(respond("I can't solve 2x+3=7"))
Notes for teachers: Explain each regex and why we use match vs search. Point out the last rule is a catch-all. Encourage students to add tests for the math pattern.
JavaScript: Basic pattern matching (Node.js)
const rules = [
{ pattern: /I need (.*)/i, templates: ["Why do you need {0}?", "Would getting {0} help?"] },
{ pattern: /I can't (.*)/i, templates: ["What stops you from {0}?", "Have you tried breaking {0} into smaller steps?"] },
{ pattern: /Solve (.*)/i, templates: ["I can try. Do you want steps for {0}?"] },
{ pattern: /(.*)/i, templates: ["Tell me more."] }
];
function swapPronouns(text) {
const map = { 'I': 'you', 'me': 'you', 'my': 'your', 'you': 'I' };
return text.split(/\s+/).map(w => map[w] || w).join(' ');
}
function respond(text) {
for (const r of rules) {
const m = text.match(r.pattern);
if (m) {
const phrase = swapPronouns(m[1] || '');
const template = r.templates[Math.floor(Math.random() * r.templates.length)];
return template.replace('{0}', phrase);
}
}
}
console.log(respond("I can't factor x^2 - 5x + 6"));
Practical regex patterns for classroom use
Start with a small pattern library. These are classroom-tested and safe for students:
- /I need (.*)/ — captures needs or requests
- /I can't (.*)/ — captures problems and blocks
- /I (?:feel|am) (.*)/ — emotion or state
- — math request trigger
- — calculus trigger
Encourage students to test with both uppercase and lowercase inputs, and to escape special characters when matching math (like ^ or +).
Connecting to interactive equation solvers
An exciting extension is having the ELIZA-like bot recognize math-related requests and route them to an interactive equation solver. This demonstrates how parsing and intent detection feed deterministic tools—similar to how modern assistant pipelines work.
Two extension options
- Local algebra helper: For patterns like "Solve 2x+3=7", implement a small algebra parser that isolates x. Great for reinforcing algebra concepts.
- SymPy or remote API: Parse the math phrase, convert to a SymPy expression server-side, request steps, and return a simplified explanation. This models an agent that combines pattern matching with a specialized math engine.
Example flow for a math request:
- Regex detects "solve" or "derivative" and captures the expression.
- Bot normalizes the expression (replace '^' with '**', remove spaces around operators).
- Either use built-in code to solve or POST to a math API and present the returned steps to the user.
Assessment and rubric
Assess both coding and computational thinking. A simple rubric:
- Rule coverage: Student implemented at least 6 pattern-response rules (20%).
- Regex correctness: Patterns correctly match test inputs (20%).
- Heuristic logic: Pronoun swap, catch-all response, and context memory (20%).
- Presentation: Explanation of how three rules work and one failure case (20%).
- Extension: Optional math solver integration or UI polish (20%).
Classroom discussion prompts and reflection
Use the project as a springboard to bigger topics. Sample prompts:
- What made the bot feel human sometimes? What made it fail?
- How does a rule-based bot differ from an LLM? Where is each useful?
- When might a pattern-matching approach be safer than a generative model?
- How would you handle abusive or sensitive inputs in a classroom bot?
Safety, ethics, and AI literacy (2026 considerations)
By early 2026, educators must address AI safety and ethics in class projects. For this unit:
- Explicitly block or redirect sensitive topics (create a rule for keywords and guide users to support resources).
- Log conversations with student consent for analysis, focusing on error patterns.
- Teach students about the ELIZA effect—why humans attribute understanding to shallow systems—and contrast it with current LLM behavior, including hallucination risks and mitigation strategies (e.g., tool grounding).
Real classroom examples and impact
Teachers who used ELIZA demos in late 2025 found students became more skeptical of flashy AI demos and more curious about how inputs are transformed into outputs. One middle-school teacher reported students redesigned rules after analyzing failure transcripts—an authentic debugging exercise that revealed computational thinking growth.
Extensions and future-proofing the project
Want to scale this into a semester-long module or link it to the Interactive Equation Solver Tools pillar? Try these advanced paths:
- Build a pipeline where intent detection (regex) routes to specialized modules: math solver, glossary lookup, or small knowledge base—the same tool chaining patterns used in production assistants.
- Introduce simple statistical techniques: word frequency matching or cosine similarity between short vectors (using TF-IDF) to show the bridge between rules and ML.
- Deploy as a web app and collect anonymized, consented logs for a data-analysis week where students quantify common failure modes.
Teacher tips for a smooth rollout
- Prepare starter rule files so students can get immediate wins. Confidence fuels experimentation.
- Use pair programming: one student crafts regex patterns; the other writes responses and tests them.
- Model scientific inquiry: hypothesize why a rule fails, test, and document results.
- Have a fallback “safety” response for sensitive inputs and teach students to escalate when required.
Why this project prepares students for 2026 and beyond
ELIZA-style bots teach students how language processing is constructed from simple parts—an essential mental model as AI becomes more integrated in schools. By combining pattern matching, regex, and small heuristic modules with optional math solver ties, students gain practical coding experience and an understanding of tool chaining that mirrors modern assistant architectures. This is exactly the kind of hands-on AI literacy that late-2025 education initiatives called for.
Actionable takeaways (what to do tomorrow)
- Download or create a starter ELIZA script in Python or JavaScript.
- Plan 3 class sessions: history + demo, regex lab, and build/test day.
- Prepare a short worksheet with 8 sample inputs that exercise math patterns and emotional prompts.
- Decide whether to include an interactive equation solver (SymPy) as an optional extension.
- Schedule student presentations and a reflection discussion on AI limitations.
Final thoughts
Building an ELIZA-style chatbot is low-cost, high-impact classroom work. It demystifies AI, teaches tangible programming and regex skills, and creates an approachable bridge to math tool integration. Your students will leave with a clearer sense of how conversational systems are built—and where they break down—making them smarter consumers and creators of AI tools.
Call to action
Ready to run this in your class? Download our free starter kit with templates for Python, JavaScript, a printable lesson plan, and a rubric tailored for middle and high school. Try a pilot lesson and share student transcripts (anonymized) to get feedback from our community of CS teachers. Sign up now to get the starter kit and join a live workshop where we’ll walk through the SymPy math extension step-by-step.
Related Reading
- Fine‑Tuning LLMs at the Edge: A 2026 UK Playbook
- MLOps in 2026: Feature Stores, Responsible Models, and Cost Controls
- Storage Workflows for Creators in 2026: Local AI, Bandwidth Triage
- Teacher Wellbeing: Mobility, Nutrition and Micro‑Mentoring Routines for 2026
- NVLink + RISC‑V: Compatibility Matrix for GPUs, SoCs and Interconnects
- Automating Logistics Workflows with an AI-Powered Nearshore Model: Tech Stack Recommendations
- What the BBC–YouTube Talks Mean for Travel Creators: How to Pitch Short-Form Destination Series
- How RGBIC Smart Lamps Transform Home Plating and Food Photography
- A Visual Reporter’s Guide to Covering Henry Walsh’s Expansive Canvases
Related Topics
equations
Contributor
Senior editor and content strategist. Writing about technology, design, and the future of digital media. Follow along for deep dives into the industry's moving parts.
Up Next
More stories handpicked for you