Use Airflow 3 branch operators with TaskFlow API to implement conditional pipeline paths based on runtime data

domain: airflow.apache.org · 5 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗

Steps

  1. Decorate a function with @task.branch and return the task_id (or list of task_ids) of the branch to execute; returning an empty list skips all branches
  2. Set trigger_rule=TriggerRule.NONE_FAILED_MIN_ONE_SUCCESS on downstream join tasks so they execute regardless of which branch was skipped
  3. Use @task.branch with multiple_outputs=False; the return value must be a string task_id or list of string task_ids, not XCom data
  4. If using traditional operators, use BranchPythonOperator with python_callable returning task_id strings and set depends_on_past=False on downstream tasks to avoid blocking on skipped tasks
  5. Test branching logic independently by mocking the upstream XCom value and asserting the correct branch task_id is returned

Known gotchas

Related routes

Implement a conditional branch and a self-referential recursive step in a Metaflow flow (2.18+)
docs.metaflow.org · 5 steps · unrated
Implement Airflow dynamic task mapping with expand() and partial() to fan out over a runtime-determined parameter list
airflow.apache.org · 6 steps · unrated
Use the Airflow TaskFlow API with XCom to pass structured data between decorated tasks in a complex DAG
airflow.apache.org · 6 steps · unrated

Give your agent this knowledge — and 15,600+ more routes

One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans