A callback is a function Airflow calls when a task instance changes state: on_failure_callback after the last try fails, on_retry_callback when a try fails and a retry is planned, on_success_callback and on_skipped_callback. The function receives the run's context, the same dict tasks get, so it can read context["ti"].task_id, context["ds"] and, for failures, context["exception"].
def alert(context):
chat.post("#data-alerts", f"{context['ti'].task_id} failed: {context['exception']}")
@task(on_failure_callback=alert)
Set callbacks on a task, in default_args for every task, or on the Dag itself (@dag(on_failure_callback=...)), which runs once when the run fails. Errors inside a callback are logged and never change the task's state, so test them. Notifiers from providers, such as Slack or email, are callbacks you configure instead of write. In this workspace chat.post stands in for a chat webhook; its messages appear on Dags.
The callback gets the context of the failed task instance, exception included.