Built to order

AI Mental Health Support Chatbot using LLM and CBT Techniques

This project builds an AI mental health support chatbot that pairs a large language model with cognitive behavioural therapy (CBT) techniques, so it can listen with empathy, spot unhelpful thoughts and guide coping exercises. The working demo is an offline CBT companion with a mood check-in, a guided thought record and a breathing exercise, while the full build adds the Gemini API for open-ended conversation. An academic prototype, not a replacement for professional care. Suitable for B.E./B.Tech final-year projects in Computer Science, IT and AI & Machine Learning.

Chat on WhatsApp — get a quotation

AI & Machine Learning PythonFlaskSQLiteGitHTML · CSS · JavaScriptGemini APIEmpatheticDialogues datasetJSON CBT script librarySoftware
AI Mental Health Support Chatbot using LLM and CBT Techniques — project thumbnail preview
More project photos (2)

The problem

An AI mental health support chatbot using LLM and CBT techniques is a conversational web app that listens to what a user is feeling, reflects it back with empathy, and then works through the unhelpful thought behind it using structured cognitive behavioural therapy. The chatbot first acknowledges the emotion in the user's words, then guides a short CBT flow — naming the automatic thought, checking the evidence for and against it, spotting the thinking pattern, and reframing it into a balanced thought — and closes with a practical coping step such as a breathing exercise or a mood check-in. Students often feel low or anxious yet hesitate to talk to anyone, and existing chatbots either give generic motivational replies or jump straight to advice without first understanding the feeling. This project closes that gap by pairing a large language model for open, empathetic conversation with a curated CBT response engine that keeps every reply inside safe, structured therapy techniques.

SYSTEM FLOW

5 components 4 connections

Live flow
Drag to explore
100%
userStudent

Types how they feel or picks a mood on the 5-point check-in.

Follow the working sequence

How it works

The AI mental health support chatbot works in a short loop: listen, reflect, test the thought, reframe it, and close with a coping step. A user writes how they feel; the system identifies the emotion and reflects it back, so the user feels heard before any advice appears. The chatbot then asks the CBT questions in order — what happened, what thought followed, what evidence supports it, what evidence counts against it — and labels the thinking pattern, such as catastrophising. With the evidence on the table, the user writes a balanced thought with the chatbot's help, rates how they feel again, and the app saves the record. The loop closes with a practical step: a breathing exercise, a mood check-in, or a suggestion to talk to a trusted person. In the demo this loop runs offline on the curated CBT engine; in the full build the open conversation passes through the Gemini API while the CBT structure stays rule-based.

  1. The user opens the chat and describes how they feel in plain words, or picks a mood on the 5-point check-in scale.
  2. The chatbot identifies the emotion in the message and reflects it back in an empathetic opening reply.
  3. The CBT flow asks for the situation and the automatic thought, then prompts for evidence for and against it.
  4. The engine labels the thinking pattern — for example catastrophising or all-or-nothing thinking — from its 5-pattern library.
  5. The user writes a balanced thought with the chatbot's prompts, then re-rates the feeling on the same 5-point scale.
  6. The app saves the thought record and mood entry, and offers a 4–7–8 breathing exercise or a follow-up check-in to close the session.
  7. In the full build, open-ended replies are generated through the Gemini API, while the CBT steps, safety checks and mood storage stay in the app's own code.

Comparison

Approach How it replies CBT structure Use case
Generic motivational chatbot Fixed encouraging phrases None Simple demo chat
Rule-based CBT companion (this demo) Curated CBT prompts and responses Full 5-step thought record Learning CBT design offline
LLM-assisted CBT chatbot (this full build) Gemini API open conversation inside CBT steps Full 5-step thought record plus safety checks A complete, explainable project

Tech stack:

  • Python 3, Flask
  • Gemini API (full build)
  • HTML · CSS · JavaScript
  • EmpatheticDialogues dataset (reference corpus)
  • SQLite (full build)
  • JSON CBT script library (demo engine)
  • Browser local storage (demo data)
  • Git

Dataset & model details

  • Dataset: EmpatheticDialogues — approximately 25,000 human-to-human conversations grounded in emotional situations, with 32 emotion labels, released by Rashkin et al. (ACL 2019). Used as the reference corpus for empathetic response design in the full build; the demo runs on the curated CBT script library instead of a trained model.
  • Task: Empathetic response generation; input = the user's message plus the conversation history, output = an empathetic reply that stays inside the CBT flow.
  • Model: Gemini API for open-ended conversation in the full build; the demo uses a rule-based CBT engine with keyword and emotion matching over its 5-pattern library. No model is trained or fine-tuned in this project.
  • Metrics: Human rating of empathy and relevance on a sample conversation set, on a 5-point scale; design target is an average empathy rating of 4 or above in the student-run evaluation. No accuracy figure is claimed, since empathetic conversation has no single correct answer to score against.
Parameter Value
Chat interface Single-page web app, runs in a browser
Conversation engine (demo) Rule-based CBT engine, works offline
Conversation engine (full build) Gemini API for open-ended replies
CBT patterns covered 5 thinking patterns in the demo
Mood scale 5-point check-in scale
Breathing pattern 4–7–8 seconds, 4 rounds, approximately 2 minutes per session
Thought-record flow Approximately 3 minutes per record in the demo
Demo sample data 7-day mood chart with 6 of 7 check-in days
Demo worked example Feeling intensity falls from 4 to 2 on the 5-point scale after reframing
Response time (demo) Under 1 second per reply (design target, local engine)
Data storage Browser local storage, approximately 50 KB per 30 days of check-ins (expected)
Platform Any modern browser, no install needed

Project features

The chatbot's strongest capabilities are its empathetic conversation flow, its guided CBT thought record, and its mood tracking with coping exercises. The conversation flow opens by reflecting the user's emotion before offering any suggestion, so replies feel heard rather than scripted. The thought record turns a CBT session into a repeatable five-step form — situation, automatic thought, evidence for and against, thinking pattern, balanced thought — and the demo walks a sample worry about a project review through the whole flow in about three minutes. Mood tracking runs on a simple 5-point check-in scale, plotted across the week so patterns become visible, and the breathing exercise pairs a 4–7–8 paced timer with before-and-after mood logging. Together these four capabilities give the project its shape: conversation that listens, structure that teaches CBT, and tracking that shows change over time.

  • [Empathetic conversation flow] The chatbot reflects the emotion in the user's message before responding, using the Gemini API in the full build and the curated CBT engine in the offline demo.
  • [Guided CBT thought record] A five-step form — situation, automatic thought, evidence for and against, thinking pattern, balanced thought — that turns a worry into a reframed, evidence-checked thought.
  • [Thinking-pattern detection] The demo's CBT engine covers 5 common patterns — catastrophising, mind reading, all-or-nothing thinking, overgeneralising and should statements — and labels the one that matches the user's thought.
  • [Mood check-in and weekly chart] A 5-point daily mood check-in plotted across the week, so the user can see whether low days cluster around deadlines or exams.
  • [Guided breathing exercise] A 4–7–8 paced breathing timer with 4 rounds per session, logging mood before and after so the calming effect is visible.
  • [Crisis-safety response] If a message suggests the user may be unsafe, the chatbot shows crisis resources and emergency-help guidance instead of continuing the conversation.
  • [Conversation history] Past chats and thought records are saved in the browser, so the user can revisit earlier balanced thoughts when the same worry returns.

What is included

  • Complete chatbot source code (Flask backend, web frontend)
  • Curated CBT script library and 5-pattern thinking-pattern engine
  • Working demo with sample conversation, thought record and breathing exercise
  • Mood check-in and weekly chart module
  • Crisis-safety response module with helpline guidance
  • Project report PDF (background, CBT theory, LLM integration, methodology, evaluation)
  • PPT presentation for final review
  • Viva Q&A preparation document (LLM prompting, CBT flow, empathy evaluation, safety limits)

Limitations & prerequisites

  • This is an academic prototype and is not a replacement for professional mental-health care, diagnosis or treatment.
  • The demo's rule-based engine only handles the 5 thinking patterns in its library; unusual phrasing may fall back to a generic empathetic reply.
  • Empathetic conversation has no single correct answer, so no accuracy figure is claimed; evaluation is by human rating only.
  • The full build needs a Gemini API key and an internet connection; the demo works offline but cannot hold open-ended conversation.
  • Mood data is stored in the browser, so it does not sync across devices and is lost if browser data is cleared.
  • The chatbot cannot detect a crisis reliably from text alone; the safety response depends on keyword matching, so it must never be presented as a crisis service.
  • All demo conversations and mood entries are sample data created for the build, not real user data.

Frequently Asked Questions

Is this project suitable for a final-year project?

Yes — for Computer Science, IT and AI & Machine Learning programs. It demonstrates conversational AI, LLM API integration, CBT-based dialogue design, and honest evaluation of a system whose quality is judged by human raters rather than a single accuracy number. The CBT structure, the demo engine and the LLM integration give a guide three distinct technical angles to examine, and the safety limits make a strong discussion point in the viva.

Which dataset and model are used?

EmpatheticDialogues — approximately 25,000 conversations with 32 emotion labels, released by Rashkin et al. in 2019 — is the reference corpus for empathetic response design, and the full build generates open-ended replies through the Gemini API while the demo runs on a rule-based CBT engine. No model is trained or fine-tuned in this project, and no accuracy figure is claimed for empathetic replies.

Does the chatbot diagnose or treat mental-health conditions?

No — it is an academic prototype that practises supportive conversation and CBT-style thought exercises, and it does not diagnose, treat or replace professional care in any way. Its role is to demonstrate conversational AI and CBT design, not to provide clinical support. If a message suggests the user may be unsafe, the chatbot shows crisis resources and emergency-help guidance instead of continuing the conversation, and the report states this limit explicitly.

What does the demo actually do without the LLM?

The demo is a fully working offline CBT companion: it holds a sample empathetic conversation, walks a worry through the five-step thought record, labels the thinking pattern, runs the 4–7–8 breathing exercise and plots a week of mood check-ins. The only part that needs the Gemini API is open-ended conversation beyond the curated CBT scripts.

How is the chatbot evaluated if there is no accuracy score?

By human rating: a sample set of conversations is scored for empathy and relevance on a 5-point scale, with a design target of an average empathy rating of 4 or above, because empathetic conversation has no single correct answer to score against. The report also records the demo's own worked example, where the sample user's feeling intensity falls from 4 to 2 after reframing, labelled as demo sample data rather than a measured result.

Can this project be customised?

Yes — the CBT script library can be extended with more thinking patterns or college-specific stress scenarios, the mood chart can add weekly summaries, and the chat can be connected to other LLM providers or a custom fine-tuned model. A companion mobile view and a counsellor dashboard for anonymised mood trends are possible extensions, listed as future scope.

Components & software requirements
  • Python 3, Flask
  • Gemini API (full build)
  • HTML · CSS · JavaScript
  • EmpatheticDialogues dataset (reference corpus)
  • SQLite (full build)
  • JSON CBT script library (demo engine)
  • Browser local storage (demo data)
  • Git

Dataset & model details

  • Dataset: EmpatheticDialogues — approximately 25,000 human-to-human conversations grounded in emotional situations, with 32 emotion labels, released by Rashkin et al. (ACL 2019). Used as the reference corpus for empathetic response design in the full build; the demo runs on the curated CBT script library instead of a trained model.
  • Task: Empathetic response generation; input = the user's message plus the conversation history, output = an empathetic reply that stays inside the CBT flow.
  • Model: Gemini API for open-ended conversation in the full build; the demo uses a rule-based CBT engine with keyword and emotion matching over its 5-pattern library. No model is trained or fine-tuned in this project.
  • Metrics: Human rating of empathy and relevance on a sample conversation set, on a 5-point scale; design target is an average empathy rating of 4 or above in the student-run evaluation. No accuracy figure is claimed, since empathetic conversation has no single correct answer to score against.
Delivery information

Built-to-order project. Delivery timeline is shared after order confirmation based on current queue.

Support terms

Complete documentation, setup guide, and viva preparation included. Support for setup and explanation provided.

Download free synopsis (PDF)

Enter your name and WhatsApp number — the synopsis PDF downloads immediately. We may send occasional project updates on WhatsApp; no spam.

Get a quotation