Skip to content

Guard composer

Fluent Guard builder for Composer.

This module defines GuardComposer, a small builder used by Composer to add a guard conditional step fluently.

Note

This builder is not meant to be instantiated directly by users. Use Composer.guard(...) to obtain an instance and complete it with .on_success(...), .on_failure(...), and .end().

Authors

Dimitrij Ray (dimitrij.ray@gdplabs.id)

References

NONE

GuardComposer(parent, condition, output_state=None, input_map=None, retry_config=None, error_handler=None, cache_store=None, cache_config=None, name=None)

Fluent builder for a guard conditional.

Usage

composer.guard(condition).on_success(success_branch).on_failure(failure_branch).end() composer.guard(condition).on_success(success_branch).end() # failure defaults to termination

After setting the branches, call .end() to append the guard step and return back to the parent Composer.

Initialize the GuardComposer.

Parameters:

Name Type Description Default
parent Composer

The parent composer instance.

required
condition Component | Callable[[dict[str, Any]], bool]

The condition to evaluate.

required
output_state str | None

Optional state key to store condition result. Defaults to None.

None
input_map InputMapSpec | None

Unified input mapping for the condition. Defaults to None.

None
retry_config RetryConfig | None

Retry configuration. Defaults to None.

None
error_handler BaseStepErrorHandler | None

Error handler. Defaults to None.

None
cache_store BaseCache | None

Optional cache store. Defaults to None.

None
cache_config dict[str, Any] | None

Optional cache config. Defaults to None.

None
name str | None

Optional name for the resulting step. Defaults to None, in which case a name will be auto-generated with the prefix "Guard_".

None

end()

Finalize and append the guard step to the parent composer.

Returns:

Name Type Description
Composer Composer

The parent composer for continued chaining.

on_failure(branch)

Define the branch to execute when the condition is false (failed).

Parameters:

Name Type Description Default
branch BasePipelineStep | list[BasePipelineStep]

The step(s) for the failure branch.

required

Returns:

Name Type Description
Self Self

The builder instance for chaining.

on_success(branch)

Define the branch to execute when the condition is true (successful).

Parameters:

Name Type Description Default
branch BasePipelineStep | list[BasePipelineStep]

The step(s) for the success branch.

required

Returns:

Name Type Description
Self Self

The builder instance for chaining.