Metaflow provides several debugging tools to help you troubleshoot issues in your flows. This guide covers debug flags, error inspection, and debugging strategies.
When a task fails, you can inspect it using the Client API:
from metaflow import Flow, Task# Get the failed runrun = Flow('MyFlow').latest_run# Find failed tasksfor step in run: for task in step: if not task.successful: print(f"Failed task: {task.pathspec}") # Access the exception if hasattr(task, 'exception'): print(f"Exception: {task.exception}")
The @catch decorator allows flows to continue executing even when a step fails:
from metaflow import FlowSpec, step, catchclass RobustFlow(FlowSpec): @catch(var='error_info') @step def process_data(self): # This step might fail result = risky_operation() self.result = result self.next(self.end) @step def end(self): # Check if previous step failed if hasattr(self, 'error_info') and self.error_info is not None: print(f"Step failed with: {self.error_info}") # Handle the error case else: print(f"Success: {self.result}")
from metaflow import Flow# Get specific runrun = Flow('MyFlow')['123']# Access artifacts from any stepfor step in run: print(f"Step: {step.id}") # List all artifacts for artifact in step.task: print(f" Artifact: {artifact}")
@stepdef validate(self): assert len(self.data) > 0, "Data should not be empty" assert all(x > 0 for x in self.data), "All values should be positive" self.next(self.process)