Skip to content

Guard step

A guard step that can terminate pipeline execution based on a condition.

Author

Dimitrij Ray (dimitrij.ray@gdplabs.id)

References

NONE

GuardStep(name, condition, success_branch, failure_branch=None, **kwargs)

Bases: ConditionalStep

A conditional step that can terminate pipeline execution if a condition is not met.

This step evaluates a condition and either: 1. Continues execution through the success_branch if the condition is True 2. Executes the failure_branch and terminates if the condition is False

Example:

pipeline = (
    step_a
    | GuardStep(
        name="auth_check",
        condition=lambda x: x["is_authenticated"],
        success_branch=step_b,
        failure_branch=error_handling_step,
    )
    | step_c
)

Attributes:

Name Type Description
name str

A unique identifier for this pipeline step.

condition ConditionType

The condition to evaluate.

success_branch BasePipelineStep | list[BasePipelineStep]

Steps to execute if condition is True.

failure_branch BasePipelineStep | list[BasePipelineStep] | None

Steps to execute if condition is False. If None, pipeline terminates immediately on False condition.

Initializes a new GuardStep.

Parameters:

Name Type Description Default
name str

A unique identifier for this pipeline step.

required
condition ConditionType

The condition to evaluate.

required
success_branch BasePipelineStep | list[BasePipelineStep]

Steps to execute if condition is True.

required
failure_branch BasePipelineStep | list[BasePipelineStep] | None

Steps to execute if condition is False. If None, pipeline terminates immediately. Defaults to None.

None
**kwargs Any

Additional arguments to pass to ConditionalStep.

{}