Email processing orchestration

Introduction#

Mail triage: placement offers first, then everything else. Classification trees, the LLM extraction path for offers, hooks into official placement data, and how concurrency stays ordered when the inbox spikes.

Project structure#

The email processing orchestration spans several modules:

  • CLI orchestration and scheduling: main entry points and schedulers
  • Email processing services: placement and general notice classification/extraction
  • Formatting and notification: transforming events into notices and broadcasting
  • Official data integration: scraping and storing government portal data
  • Configuration and dependency injection: centralized settings and DI

Core components#

  • Priority-based orchestration: placement offers are processed first; only non-placement emails are routed to general notice classification.
  • LLM-powered classification and extraction: placement uses keyword-based classification plus LLM extraction; general notices use LLM-based classification and extraction.
  • Policy handling: placement policy updates are detected and processed separately from regular notices.
  • Official placement integration: periodic scraping of government portal data for batch-wise placement statistics.
  • Notification formatting and dispatch: placement events are transformed into notices and broadcast via configured channels.

Architecture overview#

The orchestration follows a deterministic priority flow:

  1. Fetch unread email IDs from Google Groups.
  2. For each email:
  • Attempt placement offer detection using placement_service.
  • If not a placement offer, attempt general notice classification using email_notice_service.
  • Persist results and mark email as read.
  1. Periodically scrape official placement data and integrate into the system.
  2. Broadcast unsent notices via Telegram and/or Web Push.

Detailed component analysis#

Priority-Based email handling#

  • Placement offers are processed first using a hybrid approach: keyword-based initial scoring followed by LLM validation so only final placement offers pass.
  • Non-placement emails are routed to the general notice pipeline, which relies purely on LLM classification to distinguish valid notices from spam or irrelevant content.
  • Policy updates are detected and processed separately to maintain clean separation of concerns.

Email classification and extraction pipelines#

Placement service pipeline#

  • Classification: keyword-based scoring with confidence thresholds, plus LLM validation for final placement offers.
  • Extraction: LLM-based structured extraction with retry logic and validation.
  • Privacy sanitization: removal of headers and forwarded markers.
  • Output: PlacementOffer objects persisted to database and transformed into notices.

General notice service pipeline#

  • Classification: LLM-based classification without keyword filtering; placement offers are explicitly excluded.
  • Extraction: LLM-based extraction with structured schema validation and retry logic.
  • Policy detection: separate LLM pass for placement policy updates with dedicated schema.
  • Output: NoticeDocument objects saved to database and formatted for notifications.

LLM-Powered content extraction for placement services#

  • Structured extraction prompts enforce strict schema compliance for company, roles, packages, students, and supporting details.
  • Reliable retry logic with validation error accumulation and maximum retry limits.
  • Privacy sanitization removes headers, forwarded markers, and sensitive metadata.
  • Package conversion normalizes units (e.g. LPA) and handles ranges and stipends.

Official placement service integration#

  • Scrapes official JIIT placement page for batch-wise statistics and pointers.
  • Extracts placement pointers and package distribution tables.
  • Normalizes and stores structured data for downstream analytics and notifications.

Decision trees and fallback mechanisms#

  • Placement classification decision tree:
  • Keyword-based confidence score threshold determines initial relevance.
  • LLM final validation accepts only final placement offers.
  • On rejection, the system proceeds to general notice classification.
  • General notice classification decision tree:
  • LLM-based classification excludes placement offers and spam.
  • Policy updates are detected and processed via a separate extraction pass.
  • On validation failure, retry up to configured limit; otherwise reject.
  • Fallback mechanisms:
  • Policy updates are handled independently and saved as policy documents.
  • Non-relevant emails are marked as read to prevent reprocessing.
  • Unsolicited notices are saved and broadcast via notification service.

Concurrent processing strategies and volume handling#

  • Sequential processing per email within a single orchestration loop to maintain ordering and avoid race conditions.
  • Separate schedulers for automated updates and bot commands to isolate workloads.
  • Retry logic with bounded attempts to handle transient LLM or parsing failures.
  • Daemon mode support for long-running processes with controlled logging.
  • Notification batching via NotificationService to minimize channel overhead.

Dependency analysis#

  • Centralized configuration via Settings and safe_print utilities enable consistent logging and daemon behavior across services.
  • Dependency injection is used extensively to enable testability and modular composition.
  • Email clients and database clients are instantiated per-process or per-runner to avoid cross-service coupling.

Performance considerations#

  • LLM calls are rate-limited by sequential processing; consider batching and caching for high-volume scenarios.
  • Retry logic prevents unnecessary reprocessing of unread emails; ensure exponential backoff if extending retries.
  • Database writes are optimized by upsert operations and pre-filtering of existing IDs.
  • Official placement scraping runs at 12:00 PM IST, overlapping the hourly SuperSet/email job. Those jobs coalesce and skip if an update is already running.

Troubleshooting guide#

  • Placement offers not detected:
  • Verify keyword indicators and LLM prompts are aligned with actual email content.
  • Check validation errors and retry counts in the placement pipeline.
  • General notices not appearing:
  • Confirm LLM classification prompt excludes placement offers and spam.
  • Review policy update detection and fallback handling.
  • Notification delivery issues:
  • Inspect NotificationService results and channel-specific errors.
  • Ensure database contains unsent notices and proper channel configuration.

Conclusion#

Placement offers first, then general notices. LLM classify/extract, official placement hooks, retries, and ordered concurrency when the inbox spikes. DI keeps the stages testable.