Data Flow Step Conditionals
Data flow steps in Kodexa pipelines can include conditional expressions that determine whether a step should execute. This allows you to create dynamic pipelines that adapt their behavior based on document properties, metadata, or execution context.Overview
When a pipeline step has aconditional property set, the expression is evaluated before the step executes. If the expression evaluates to true (or any truthy value), the step runs normally. If it evaluates to false (or any falsy value), the step is skipped and the pipeline continues to the next step.
Syntax
Conditionals use Python-like expression syntax powered by simpleeval. This provides a safe, sandboxed environment for evaluating expressions.Supported Operators
| Category | Operators |
|---|---|
| Comparison | ==, !=, <, >, <=, >= |
| Logical | and, or, not |
| Membership | in, not in |
| Arithmetic | +, -, *, /, % |
| Boolean | True, False |
Parentheses
Use parentheses to group expressions and control evaluation order:Available Variables
The conditional expression has access to three variables:context
The execution context - a dictionary that can be populated when the execution is created or by the project configuration.
metadata
The document’s metadata dictionary. This contains any metadata properties stored on the document being processed.
external_data
A dictionary containing all external data stored on the document, keyed by their storage key. External data is commonly used to store processing results, taxonomy outputs, or any structured data associated with a document.
Examples
Basic Conditionals
Skip step if document is already processed:Combining Conditions
Multiple metadata checks:Environment-Based Conditions
Production-only steps:Document State Checks
Check processing history:Default Values
When accessing dictionary values that might not exist, always use.get() with a default value to prevent errors:
Step Behavior When Skipped
When a step’s conditional evaluates tofalse:
- The step status is set to
SKIPPED - The document from the previous step (if any) is preserved and passed to the next step
- Processing continues with the next step in the pipeline
- The skip reason is logged for debugging
Error Handling
If a conditional expression fails to evaluate (syntax error, runtime error, etc.):- The step is automatically skipped
- The error is logged with details
- The step status indicates “Conditional evaluation failed”
- Pipeline execution continues
Best Practices
- Use descriptive metadata keys: Name your metadata fields clearly so conditionals are self-documenting.
-
Always provide defaults: Use
.get(key, default)to handle missing values gracefully. - Keep expressions simple: Complex logic should be handled in step code, not conditionals.
- Test conditionals: Verify your conditional logic works with various document states before deploying.
- Document your conditionals: Add comments in your pipeline configuration explaining why each conditional exists.
Debugging Tips
- Check the execution logs to see conditional evaluation results
- Verify the document has the expected metadata/external data before the step runs
- Use simple test expressions to isolate issues
- Remember that
None, empty strings"", empty dicts{}, and0are all falsy values
