📄 PAYMENT_ALERT_IMPLEMENTATION.md 2,786 bytes Apr 27, 2026 📋 Raw

Payment Alert Extraction - Implementation Summary

Files Modified

1. prompts/email_classify.txt

  • Added "payment_alert" as a third classification option
  • Added detection rules for payment failures, card declines, billing issues
  • Payment alerts take priority over other classifications

2. prompts/payment_alert_extract.txt (NEW)

  • New prompt template for extracting payment alert details
  • Extracts: merchant, alert_type, amount, deadline, action_needed, summary
  • Returns {"not_a_payment_alert": true} if not a genuine payment alert

3. config.py

  • Added payment_alert_extract.txt to the load_prompts() function

4. hermes.py

  • Added format_payment_alert() function to format payment alerts for Telegram
  • Adds [PAYMENT ALERT] prefix with 🚨 emoji
  • Includes merchant name, amount, deadline, and action needed
  • Updated push_pipeline_results() to handle payment alerts (sent immediately, not batched)

5. newsletter_parser.py

  • Updated classify_email() to accept payment_hint parameter
  • When payment keywords are detected, adds a hint to the LLM classifier
  • Returns "payment_alert" if LLM classifies as such

6. pipeline.py

  • Added _PAYMENT_ALERT_KEYWORDS tuple with detection phrases:
  • "payment failed", "card declined", "declined", "transaction failed"
  • "card expired", "update your payment", "payment method"
  • "subscription suspended", "account will be canceled"
  • "your payment could not be processed", "payment was unsuccessful"
  • "unpaid invoice", "past due", "overdue payment"
  • Added _scan_payment_alert() function for fast keyword pre-scan
  • Added parse_payment_alert_with_llm() function to extract details via LLM
  • Updated _triage_email() to pass payment hints to classifier
  • Updated _process_emails_inner() to handle payment_alert classification:
  • Extracts alert details via LLM
  • Sends immediate notification via Telegram
  • Ingests into Family Brain for RAG retrieval
  • Updated _process_webhook_email_inner() with same payment alert handling
  • Added payment_alerts key to result dictionaries

Behavior

When a payment alert email arrives:
1. Fast keyword scan detects payment-related keywords
2. Email is classified as "payment_alert" by LLM
3. Details extracted: merchant, amount, deadline, action needed
4. Immediate Telegram notification sent with [PAYMENT ALERT] prefix
5. Email ingested into Family Brain for reference

Testing

Quick test of keyword detection:

from family_assistant.pipeline import _scan_payment_alert

_scan_payment_alert("Netflix: Payment declined", "Your card was declined")
# Returns: True

Deployment

All changes are in the family_assistant package. No database changes, no new CLI commands, no Icarus modifications.