Ayushi
11/14/2025, 12:29 PMElena Khaustova
11/14/2025, 3:49 PMif/else node execution by default, because node execution order is determined by a topological sort of nodes based on inputs and outputs, not runtime conditions.
However, there are workarounds:
1. Use parameters inside a node - have one node that checks a flag and internally decides which logic to run. Pipeline sees it as one node.
def conditional_node(param, data1, data2):
if param:
return process_node1(data1)
else:
return process_node2(data2)
2. Use node tags - assign different tags to nodes and run only the branch you want based on a condition.
Kedro allows selective execution of nodes by tags. You can create two nodes:
node_1 = node(func=process_node1, inputs="data1", outputs="out1", name="node_1", tags=["branch1"])
node_2 = node(func=process_node2, inputs="data2", outputs="out2", name="node_2", tags=["branch2"])
Then conditionally run the pipeline:
with KedroSession.create(...) as session:
if condition:
session.run(tags=["branch1"])
else:
session.run(tags=["branch2"])