Conditional Execution π
flowyml supports dynamic pipeline execution paths based on runtime conditions. Build smart workflows that adapt to data quality, model performance, or external factors.
What you'll learn
How to build adaptive pipelines that change behavior based on data. Real-world pipelines aren't linear β they need to make decisions.
Why Conditional Logic Matters
Without conditional logic: - Manual intervention: Stopping pipelines manually if accuracy is low - Rigid workflows: One size fits all, regardless of data volume or quality - Separate pipelines: Maintaining "Training" and "Deployment" pipelines separately
With flowyml conditional logic: - Automated decisions: "If accuracy > 90%, deploy. Else, retrain." - Adaptive behavior: "If data > 1GB, use Spark. Else, use Pandas." - Unified workflows: Handle edge cases within the same pipeline
Conditional Patterns
π Conditional Steps
You can use the conditional decorator or utility to define branching logic.
Using If Condition
Skipping Steps
You can also conditionally skip steps.
The Execution Context (ctx)
When writing conditions, you have access to a rich ctx object that allows you to inspect the state of the entire pipeline run.
Accessing Step Outputs
You can access the outputs of previous steps using ctx.steps:
Working with Assets (Typed Artifacts)
If your steps return Model, Dataset, or Metrics objects, you can access their metadata directly:
Asset Metadata
The metadata attribute in the context is a merged dictionary containing both the Asset's properties and tags.
Accessing Context Parameters
You can access pipeline parameters defined in your context():
Detailed Pattern Examples
Pattern 1: Metrics-Based Deployment
Use Metrics assets to make complex decisions.
Pattern 2: Multi-Environment Logic
Build one pipeline that behaves differently based on the environment.
Decision Guide: Control Flow
| Pattern | Use When | Example |
|---|---|---|
If / Switch |
Branching logic: Choose between different paths | Deploy vs. Retrain |
skip_if |
Optional steps: Skip a step based on a flag | Skip upload in dry_run |
Asset Access |
Data-driven decisions: Branch based on metrics | Deploy if F1 > 0.9 |
Best Practice
Keep conditions simple. If your logic is complex, move it into a dedicated @step that outputs a boolean flag, then check that flag in the If condition.