<@ULVA73B9P> how can I make a dropdown with str parameters list in the Prefect UI flow launch popup ...
f
@Marvin how can I make a dropdown with str parameters list in the Prefect UI flow launch popup in Prefect 3?
m
thought for 141.2 seconds
In Prefect 3, the Launch form will automatically render a dropdown when a flow parameter is typed as either: - typing.Literal with a fixed set of string options - An enum.Enum (ideally a str enum for string values) Examples:
Copy code
from typing import Literal
from prefect import flow

@flow
def my_flow(environment: Literal["dev", "staging", "prod"] = "dev"):
    # In the UI, 'environment' is a dropdown with the three choices
    ...
Copy code
from enum import Enum
from prefect import flow

class Environment(str, Enum):
    DEV = "dev"
    STAGING = "staging"
    PROD = "prod"

@flow
def my_flow(environment: Environment = Environment.DEV):
    # In the UI, 'environment' is a dropdown with the three choices
    ...
Notes: - The parameter is required if you don’t provide a default; adding a default sets the initial selection in the dropdown. - For string-valued enums, subclass both str and Enum (as shown) so the schema is typed as a string and renders correctly. - The choices must be static (defined in code). Dynamic, runtime-populated dropdowns aren’t supported in the Launch form; if you need that, accept a free-form string and validate it inside the flow. Helpful references: - Python Literal: typing.Literal - Python Enum: enum.Enum - Prefect flows and parameters overview: Prefect Docs (see the Flows/Parameters section) If you share your current parameter signature, I can suggest the minimal change to make it render as a dropdown.