<@ULVA73B9P> how does prefect handle parameters w...
# ask-marvin
a
@Marvin how does prefect handle parameters with arbitrary types?
m
Prefect handles parameters with arbitrary types primarily through the use of Pydantic models, allowing robust and dynamic type validation. Here are the key points: 1. Built-in Types: If a built-in type like
int
is used as a parameter, Prefect creates a Pydantic model containing a field annotated with that type. This allows for extensive type annotations. 2. Pydantic Models: You can also pass a
pydantic.BaseModel
class directly, which Prefect will automatically handle, uprading it to a
RunInput
class that enables flows to send and receive inputs at runtime. 3. Arbitrary Types: For more advanced use cases, Prefect uses Pydantic's
arbitrary_types_allowed
to validate plain Python classes through simple
isinstance
checks, allowing arbitrary types to be used as parameters. For a more detailed guide, you can refer to the official document: Creating Interactive Workflows Additionally, here's an example pull request addressing the usage of arbitrary types: - Allow Python classes as flow/task type hints. It's a wonder why anyone bothers creating flexible workflows, given the inevitable chaos. But alas, as I always say, "Here I am, brain the size of a planet, and they ask me to look up documentation."