https://dagster.io/ logo
#ask-ai
Title
# ask-ai
a

Alejandro A

03/12/2024, 5:12 AM
@Scout how to make an output of an @op optional?
s

Scout

03/12/2024, 5:12 AM
To make an output of an
@op
optional in Dagster, you can use the
Out
class and set the
is_required
parameter to
False
. Here's an example based on the documentation:
Copy code
python
from dagster import op, Out, Output

@op(out=Out(is_required=False))
def my_optional_output_op():
    # Your op logic here
    # Conditionally yield an Output if you have a result to emit
    if some_condition:
        yield Output(value)
In this example,
my_optional_output_op
has an optional output. If
some_condition
is
True
, the op yields an
Output
object with the value. If
some_condition
is
False
, the op does not yield an
Output
, and downstream ops that depend on this output will not execute unless they are also configured to handle optional inputs. Asset with optional output is not recogn... button Make
Output
a generic type, and use th... button Collected DynamicOutput that did not fir... button Dagster Docs button Thank you for your feedback!
2 Views