Skip to content

Commit f87f325

Browse files
committed
Output schema
1 parent ddc9e32 commit f87f325

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

src/zenml/pipelines/dynamic/pipeline_definition.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@
2020
List,
2121
Optional,
2222
Set,
23+
Type,
2324
Union,
2425
)
2526

26-
from pydantic import ConfigDict, ValidationError
27+
from pydantic import BaseModel, ConfigDict, ValidationError, create_model
2728

2829
from zenml import ExternalArtifact
2930
from zenml.client import Client
@@ -34,6 +35,9 @@
3435
should_prevent_pipeline_execution,
3536
)
3637
from zenml.steps.step_invocation import StepInvocation
38+
from zenml.steps.utils import (
39+
parse_return_type_annotations,
40+
)
3741
from zenml.utils import dict_utils, pydantic_utils
3842

3943
if TYPE_CHECKING:
@@ -280,4 +284,22 @@ def _compute_output_schema(self) -> Optional[Dict[str, Any]]:
280284
Returns:
281285
The output schema for the pipeline.
282286
"""
283-
return None
287+
try:
288+
outputs = parse_return_type_annotations(self.entrypoint)
289+
model_fields = {
290+
name: (output.resolved_annotation, ...)
291+
for name, output in outputs.items()
292+
}
293+
output_model: Type[BaseModel] = create_model(
294+
"PipelineOutput",
295+
__config__=ConfigDict(extra="forbid"),
296+
**model_fields,
297+
)
298+
return output_model.model_json_schema(mode="serialization")
299+
except Exception as e:
300+
logger.debug(
301+
f"Failed to generate the output schema for pipeline "
302+
f"`{self.name}: {e}. This means that the pipeline cannot be "
303+
"deployed.",
304+
)
305+
return None

0 commit comments

Comments
 (0)