Template
Drafted-email output validator
Last updated
From Section 12. A short Python check that runs on a drafted email before a human sees it. Illustrative, not a complete production service.
A short Python check that runs on a drafted email before a human sees it. Illustrative, not a complete production service.
extract_company_names is left for you to implement. Banned phrases and the word limit are examples; replace them with your own standards.
BANNED = ["i hope this finds you well", "revolutionize", "synergy",
"as an ai", "unlock", "game-changer"]
def validate_email(draft, record, approved_proof_points, max_words=90):
body = draft["body"].lower()
errors = []
if len(draft["body"].split()) > max_words:
errors.append("too_long")
if any(b in body for b in BANNED):
errors.append("banned_phrase")
if record["first_name"].lower() not in body and record["company"].lower() not in body:
errors.append("no_recipient_reference")
for name in extract_company_names(draft["body"]):
if name not in (record["company"], *approved_proof_points["customers"]):
errors.append(f"unapproved_company_mention:{name}")
if "{{" in draft["body"] or "}}" in draft["body"]:
errors.append("unfilled_template_variable")
return errors