---
name: "reply-classifier"
description: "Build a reply classifier for outreach: define a small label set where each label has one action, label 100 or more real replies as a test set, build a rules baseline for opt-outs, bounces, out-of-office and clear intents, add a language model for the remainder, parse return dates from out-of-office messages, route each label to Slack and the CRM, send low-confidence replies to a person, and measure precision and recall by label. Use when replies are read late or by hand."
---

# Reply classifier

## Goal
Hot replies reach a person within the hour, opt-outs are honoured immediately, out-of-office replies pause sequences until people are back, and nothing sits unread. Part of GTM engineering. Fed by: multi-channel-orchestrator, inbox-infrastructure-stack. Feeds: attribution-ledger, deliverability-monitor, crm-hygiene-pipeline, experiment-harness.

## When to use
- Replies pile up in a shared inbox.
- Auto-replies and bounces hide real answers.
- Opt-outs are processed by hand.

## Inputs
- Reply text, subject, sender, received date, and the original message and campaign id.
- A label set agreed with sales.
- At least 100 real replies labelled by a person.
- Slack or chat channels, and the CRM fields to write.

## Data model
`replies`: `reply_id, received_at, from_email, subject, body, campaign_id, prospect_id`
`classified`: `reply_id, label, confidence, return_date, route, reviewed_by, reviewed_at`
`labels.md`: label, definition, action, response time target

## Step 1. Define labels
Keep them few and distinct. Each label has one action. A good starting set: `interested`, `referral`, `not_interested`, `opt_out`, `out_of_office`, `bounce`, `wrong_person`, `unknown`. Write a two-line definition for each, with an example. If two labels lead to the same action, merge them.

## Step 2. Build the test set
Label 100 or more real replies by hand, including every label. Two people label a sample of 30 and compare to find fuzzy definitions. Keep the test set out of any prompt or rule tuning, or you will measure memory and not skill.

## Step 3. Rules baseline
Test in this order:
1. `opt_out`: phrases such as "unsubscribe", "remove me", "stop emailing", "do not contact".
2. `bounce`: mailer-daemon, "delivery status notification", "undeliverable".
3. `out_of_office`: "out of office", "automatic reply", "on leave", "away until".
4. `wrong_person`, `referral`, `not_interested`, then `interested`.
Anything that matches nothing is `unknown`. Run `scripts/classify_replies.py eval labelled.csv`.

## Step 4. Add a model for the rest
Send only the replies the rules mark `unknown` or low confidence to a language model. In the prompt include: the label definitions, 3 examples per label from your own data, the original outreach and the reply, and a request for JSON with `label`, `confidence` and a one-line reason. Do not let the model write or send any reply. Measure it on the same test set.

## Step 5. Parse return dates
For out-of-office replies, look for phrases like "back on", "returning", "until" followed by a date. Handle month names, ISO dates, and dates without a year (use the next occurrence after the received date). If no date is found, snooze a default number of days and mark `date_source: default`. Never invent a date.

## Step 6. Route
Use the routing map. For example: interested to a hot-replies channel with the prospect, the last email and a link to the CRM record; referral to a channel for adding the new contact; opt-out to immediate suppression across all tools; bounce to invalid-email handling and a count for deliverability-monitor; out-of-office to a snooze. Always include the original text in the Slack message.

## Step 7. Human review and improvement
Anything under your confidence line (for example 0.7) goes to a review channel. Reviewers correct labels. Add corrected replies to the test set. Re-measure monthly.

## Tool options
Your sending tool's reply webhooks or inbox API for intake. A small script for rules. A language model API for the rest. Slack or Teams for routing. A CRM for tasks and suppression. Choose what you already use and keep an audit log of every classification.

## Output
`classified.csv` and an evaluation report with precision and recall by label.

## Success metrics
- Recall for `opt_out` and `interested` (the labels where a miss costs most).
- Median time from reply to human for interested replies.
- Share of replies sent to review.
- Accuracy of return dates on out-of-office replies that state one.
- Opt-outs processed within the legal window, ideally immediately.

## Guardrails
- Opt-outs and "stop" messages are honoured immediately, everywhere, and never overwritten by a later automation.
- Replies contain personal data. Limit who sees them and keep a retention rule.
- A person sends every response. The classifier only labels and routes.
- Do not send reply text to a service you have not approved for personal data.
- Keep an audit trail: input, label, confidence, route.
