AI Email Reply Assistant Project

Artificial Intelligence project 07

AI Email Reply Assistant Project

Build a complete email reply assistant workflow with reproducible Python code, transparent inputs, reviewable output, and responsible-use limits.

Explore AI training in VizagView all project ideas

AI objective

Draft a safe starting reply by retrieving the closest approved template without sending any message.

Data or knowledge source

Four approved response templates for course information, scheduling, billing, and technical support.

Requirements

  • Python 3.10 or later
  • A terminal or command prompt
  • python -m pip install scikit-learn
  • About 45-60 minutes to build and review

How the system works

Compare the incoming message with template descriptors using TF-IDF cosine similarity and fall back to human review below the threshold.

Validation checklist

  • The program only returns approved text
  • No email is sent automatically
  • Low confidence uses a neutral fallback
  • The selected category and score are visible

Complete Python code

Save the program as ai_email_reply_assistant.py. The code runs locally and requires no paid API key or model download.

"""Draft reviewable email replies from approved templates."""

from __future__ import annotations

from dataclasses import dataclass
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.metrics.pairwise import cosine_similarity


TEMPLATES = [
    ("request course information syllabus topics", "course_information", "Thanks for your interest. Please review the current course page for the syllabus, duration, and prerequisites."),
    ("ask class schedule batch timing", "schedule", "Thanks for checking. Current batch dates and timings are available from the training support team."),
    ("payment invoice receipt refund", "billing", "Thanks for letting us know. Please share the transaction reference through the official support channel so the billing team can review it."),
    ("technical error login upload access", "technical_support", "Sorry about the difficulty. Please share the exact error, device, browser, and steps to reproduce through the support channel."),
]


@dataclass(frozen=True)
class Draft:
    category: str | None
    text: str
    confidence: float


def draft_reply(message: str, threshold: float = 0.12) -> Draft:
    prompts = [item[0] for item in TEMPLATES]
    vectorizer = TfidfVectorizer(ngram_range=(1, 2), stop_words="english")
    matrix = vectorizer.fit_transform(prompts + [message])
    scores = cosine_similarity(matrix[-1], matrix[:-1])[0]
    index = int(scores.argmax())
    confidence = float(scores[index])
    if confidence < threshold:
        return Draft(None, "Thank you for your message. A team member will review it and respond through the official support channel.", confidence)
    return Draft(TEMPLATES[index][1], TEMPLATES[index][2], confidence)


def main() -> None:
    print(draft_reply("Please send the course syllabus and topics"))
    print("Draft only: verify facts and recipients before sending any email.")


if __name__ == "__main__":
    main()

Run the project

  1. Create and activate a virtual environment.
  2. Install dependencies with python -m pip install scikit-learn when packages are required.
  3. Run python ai_email_reply_assistant.py.
  4. Review confidence, fallbacks, sources, or error metrics rather than accepting output automatically.
  5. Test additional normal, edge, unsupported, and adversarial inputs.

Expected output

A reviewable draft, category, and similarity confidence.

Accuracy, privacy, and responsible-use limits

A draft can still be wrong, stale, or addressed to the wrong person. Verify facts, recipients, attachments, privacy, promises, and tone before sending.

Ways to extend the project

Add approval workflow, language variants, customer-safe redaction, template ownership, audit logging, and feedback-based threshold tuning.

Continue learning Artificial Intelligence

Try the next project, return to the Softenant project library, or explore the AI training in Vizag for guided NLP, retrieval, evaluation, automation, and responsible AI practice.