Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save petrosDemetrakopoulos/049c3f023761264a829c251d17be0804 to your computer and use it in GitHub Desktop.
Save petrosDemetrakopoulos/049c3f023761264a829c251d17be0804 to your computer and use it in GitHub Desktop.
Mail classification using AI waterfall
import re
def classify_email_basic(email_content, subject):
# Support tickets
if re.search(r'\b(help|support|issue|problem|bug|error)\b', subject.lower()):
return 'support'
# Sales inquiries
if re.search(r'\b(quote|pricing|purchase|buy|demo)\b', subject.lower()):
return 'sales'
# HR/Recruitment
if re.search(r'\b(job|career|interview|resume|hiring)\b', subject.lower()):
return 'hr'
# If no pattern matches, escalate to LLM
client = OpenAI(api_key=API_KEY)
prompt =
f"""
Classify the following email into one of the following categories
1. Support - For support tickets and issues
2. Sales - For sales inquiries, pricing etc.
3. HR - For recruitment inquiries, interviews scheduling etc.
{subject} {email_content}
"""
llm_classification = client.responses.create(model='gpt-4.1', input=prompt).output_tex
return llm_classification
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment