powerful-australia-73346
07/03/2025, 10:40 AMjolly-florist-66728
07/03/2025, 10:40 AMreturn t1(), t2()
.
2. NamedTuple: Define a NamedTuple type and return it, e.g., return MyOutputs(a=t1(), b=t2())
.
3. Dataclass: Use a dataclass (with JSON serialization support) and return an instance, e.g., return MyDataClass(a=t1(), b=t2())
.
All these approaches are supported and strongly typed in Flyte workflows and subworkflows, as described in the Flyte user guide and demonstrated in Flyte's type hints tests.
Would you like more detail or code examples for each syntax?
Sources:
- Flyte user guide
- Flyte's type hints tests 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.powerful-australia-73346
07/03/2025, 10:42 AMjolly-florist-66728
07/03/2025, 10:42 AMvalueX
, valueY
, valueZ
), ensure it supports JSON serialization (e.g., using mashumaro.mixins.json.DataClassJSONMixin
or dataclasses_json
for older Flytekit versions), and return an instance of this dataclass from your workflow or subworkflow. Flyte will serialize the dataclass as a single complex JSON object. See the Flyte dataclass documentation and user guide for examples.
Would you like a step-by-step code example?
Sources:
- Flyte user guide: dataclass
- Flyte dataclass documentation 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.powerful-australia-73346
07/03/2025, 10:44 AMjolly-florist-66728
07/03/2025, 10:44 AM@dataclass
decorator; for older versions, add @dataclass_json
or inherit from DataClassJSONMixin
. Example:
from dataclasses import dataclass
import flytekit
from flytekit import task, workflow
@dataclass
class MyResult:
valueX: int
valueY: str
valueZ: float
@task
def make_result(x: int, y: str, z: float) -> MyResult:
return MyResult(valueX=x, valueY=y, valueZ=z)
@workflow
def wf(x: int, y: str, z: float) -> MyResult:
return make_result(x=x, y=y, z=z)
This will return a JSON object with fields valueX
, valueY
, and valueZ
. See Flyte dataclass docs for more.
Would you like more detail or an example with custom serialization?
Sources:
- Flyte user guide: dataclass 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.powerful-australia-73346
07/03/2025, 10:47 AMjolly-florist-66728
07/03/2025, 10:47 AMpowerful-australia-73346
07/03/2025, 10:51 AMjolly-florist-66728
07/03/2025, 10:51 AMfrom dataclasses import dataclass
@dataclass
class Inner:
a: int
b: str
@dataclass
class Outer:
inner: Inner
c: float
This is supported and will serialize/deserialize correctly in Flyte tasks and workflows (Flyte dataclass docs).
Would you like a full Flyte task/workflow example?
Sources:
- Flyte user guide: dataclass 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.