<@ULVA73B9P> A flow has a string as parameter, how...
# marvin-ai
m
@Marvin A flow has a string as parameter, how to display a list of restricted values on the cloud UI when running by hand?
m
thought for 124.9 seconds
Yes—restrict the choices by typing the parameter as a Literal or Enum. Prefect 3.x generates a JSON Schema with an enum, and the Cloud UI will render it as a dropdown when you click Run. - Simplest (Literal):
Copy code
from typing import Literal
from prefect import flow

@flow
def my_flow(env: Literal["dev", "staging", "prod"] = "dev"):
    print(env)
- With an Enum (handy if you want a named type):
Copy code
from enum import Enum
from prefect import flow

class Env(str, Enum):
    dev = "dev"
    staging = "staging"
    prod = "prod"

@flow
def my_flow(env: Env = Env.dev):
    print(env)
- If you want labels/descriptions or multiple constrained fields, use a Pydantic model:
Copy code
from typing import Literal
from pydantic import BaseModel, Field
from prefect import flow

class Params(BaseModel):
    env: Literal["dev", "staging", "prod"] = Field(
        default="dev", description="Target environment"
    )

@flow
def my_flow(params: Params):
    print(params.env)
Tip: After changing the allowed values, redeploy so the UI form updates. Docs: Form-building in Prefect 3