📬 Airflow Failure Alert Templates

đź•’ June 23, 2025

Improve your Airflow failure emails with simple templates and customizable callbacks—engineer-friendly and easy to extend. GitHub repo


đźš© Why Customize Airflow Alerts?

Default Airflow alert emails are basic and lack key context. With minimal setup, you can:

  • Improve visual clarity
  • Add metadata (DAG tags, retries, links, owners)
  • Include recovery tips or failure history

đź§° Option 1: Simple Template-Based Alerts

This approach uses Airflow’s built-in support for custom subject and HTML email templates.

Files

Configuration

In airflow.cfg:


[email]
html_content_template = /path/to/email_body_template.html
subject_template = /path/to/email_subject_template.html

Or as environment variables:


AIRFLOW__EMAIL__HTML_CONTENT_TEMPLATE=/path/to/email_body_template.html  
AIRFLOW__EMAIL__SUBJECT_TEMPLATE=/path/to/email_subject_template.html

Benefits

  • Clean visual layout
  • Rich metadata (task ID, DAG ID, links, retries)
  • No code changes

⚙️ Output (Basic Template)

On task failure, it uses this subject template:

{% if task_instance.try_number > task.retries %}
🚨 [Airflow Alert] FINAL FAILURE ❌ — {{ dag.dag_id }}.{{ task.task_id }} | Exec: {{ execution_date }}
{% else %}
⚠️ [Airflow Alert] RETRY {{ task_instance.try_number }}/{{ task.retries + 1 }} — {{ dag.dag_id }}.{{ task.task_id }} | Exec: {{ execution_date }}
{% endif %}

Basic failure Image


đź§  Option 2: Advanced Alerts with Python Callback

For more control and richer alerts (e.g., run history, recovery tips), use a custom on_failure_callback.

Files

Highlights

  • Injects DAG/task metadata dynamically
  • Includes last 5 DAG run statuses
  • Optional recovery guidance
  • Flexible to extend (Slack, PagerDuty, etc.)

đź§Ş Output

Alerts look like this when powered by the custom callback:

Email generated with custom callback


âś… Conclusion

Clear and contextual alerts aren’t just a “nice-to-have” — they’re essential for fast recovery, reliable systems, and a happier on-call experience.

If you’re setting up alerts for an engineering team:

  • Start with the simple HTML templates for an instant visual upgrade
  • Move to a custom callback when you need logic, historical insight, or extensibility
  • Both methods are battle-tested and production-friendly

Want to try it out?

→ Explore the GitHub repo
→ Contributions and suggestions welcome!