Define workflow inputs

Define the inputs to a workflow by adding parameters to the function definition.

from prefect import flow


@flow
def my_workflow(name: str = "World"):
    return f"Hello, {name}!"

Pass arguments to the function call to provide inputs to the workflow.

my_workflow(name="Marvin")

Validate inputs

By default, Prefect will validate the types of inputs to your workflow.

from prefect import flow


@flow
def my_workflow(name: str = "World"):
    return f"Hello, {name}!"

my_workflow(name=1) # This will fail with a type validation error

To turn off type validation, set the validate_parameters parameter to False:

from prefect import flow


@flow(validate_parameters=False)
def my_workflow(name: str = "World"):
    return f"Hello, {name}!"

my_workflow(name=1)

If you use pydantic, parameters typed with a BaseModel subclass will be coerced to the appropriate types and validated.

from prefect import flow
from pydantic import BaseModel


class Model(BaseModel):
    a: int
    b: str


@flow
def flow_that_validates_parameters(model: Model): ...

flow_that_validates_parameters(
    model={"a": "WRONG", "b": "fine"}
)