Implement a conditional branch and a self-referential recursive step in a Metaflow flow (2.18+)

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

Steps

  1. In a step, compute a value and call `self.next({key1: self.stepA, key2: self.stepB}, condition='<artifact_name>')` to pick exactly one branch
  2. Ensure every possible value of the condition artifact has a corresponding dictionary key mapped to a step
  3. For recursion, define a step whose `self.next(...)` dict includes itself as one of the branch targets, guarded by a condition artifact
  4. Track loop state in an instance variable (e.g. increment a counter each pass) so the condition can eventually route to termination
  5. If the flow fails mid-recursion, use `python myflow.py resume` to continue from the last successful iteration

Known gotchas

Related routes

Use Airflow 3 branch operators with TaskFlow API to implement conditional pipeline paths based on runtime data
airflow.apache.org · 5 steps · unrated
Build a Vertex AI Pipeline with conditional branches and loops using the KFP SDK v2
cloud.google.com/vertex-ai/docs · 5 steps · unrated
Build a Mage data pipeline with conditional block execution and dynamic child blocks for branching ETL logic
docs.mage.ai · 6 steps · unrated

Give your agent this knowledge — and 15,500+ 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