Hello <@ULVA73B9P> what can you tell me about Depl...
# ask-marvin
j
Hello @Marvin what can you tell me about Deployment Parameters in UI, is it possible to make a list of specified option? If it does exist, do you need to use Pydantic to achieve this?
m
In Prefect, the way you manage deployment parameters for your flows seems to be through the deployment YAML configuration or UI, as default parameter values can be provided in the
deployment.yaml
. However, the direct ability to create a list of specified options for deployment parameters in the Prefect UI is not explicitly mentioned. For this reason, I cannot confirm whether there is a predefined way to create a dropdown or selection list for parameters in the Prefect UI. Additionally, editing
deployment.yaml
is possible before running
prefect deployment apply
, and changing parameter values through the UI affects future flow runs that are based on that deployment. As for using Pydantic, there's no information extracted that indicates the necessity or method to use Pydantic models with Prefect Deployment Parameters. Pydantic is commonly used in Python for data validation and settings management, but Prefect's documentation does not explicitly state its use in the context of deployment parameters. For a more specific answer regarding creating a list of specified options and the use of Pydantic with Prefect, I would suggest reaching out to the Prefect community or checking Prefect's official documentation and GitHub repository. If necessary, I can search Prefect's GitHub issues for more related information. Would you like me to do that for you?
🧐 1
k
oh I think I know what you're looking for. like a drop down for a param in the ui?
🐐 1
j
yessss doesn't need to be dynamic, I can hardcode them. I swore I saw this somewhere and am blanking haha
k
Literal
🙏 1
I am on my phone so I don't have an example on hand
n
or an enum
Copy code
from enum import Enum

from prefect import flow


class CardinalDirection(Enum):
    NORTH = "north"
    SOUTH = "south"
    EAST = "east"
    WEST = "west"

@flow
def where_to_go(direction: CardinalDirection):
    print(f"Going {direction.name}!")

if __name__ == "__main__":
    where_to_go.serve("enums")
👀 1
k
ooh
j
Thanks Kevin & Nate! I think during the Prefect course I took back in fall, someone mentioned using Pydantic models for input or something, is that something you all have heard of? Or am I way off haha. And if it is possible, is it overkill
n
yeah you can use a BaseModel instance to give yourself a nice form in the UI, e.g.
🤩 1
j
This is incredible, thank you so much 🙏
n
catjam
catjam 2
k
@Nate I have been following this pattern and it has worked out well so far. However, starting yday the UI no longer picks up the pydantic model. This is all I am seeing when
config
is a Pydantic model. Attached the snippet for the pydantic model here too. Any idea why this is?
Copy code
class TestConfig(BaseModel):
    environment: Environment = (
        Field(..., description="The environment to send the API requests to"),
    )
    df_uri: str | S3URI = Field(
        default=DEFAULT_URI,
        description="S3 URI of the csv. Must contain one of these columns ['content_id', 'video_id', 'image_id']",
    )
    garm_model: str = Field(
        default="xxx", description="Name of the garm model"
    )
    decimals: int = Field(
        default=3, description="Decimal places when comparing results"
    )
n
hmm my example above is working fine for me this part looks odd to me
Copy code
environment: Environment = (
        Field(..., description="The environment to send the API requests to"),
    )
this says that
environment
is a thing of type
Environment
and has a default value of a
tuple
of
Field
objects of length one, which I don't think is what you want maybe you want this instead?
Copy code
class TestConfig(BaseModel):
    environment: Environment = Field(..., description="The environment to send the API requests to")
k
Oh wow I totally missed it, yes it works now!
Thanks Nate!
I spent 30 minutes banging my head against the wall over this...
n
😄 no worries
glad you got it resolved
k
Does the pydantic model work the same when using
prefect.yaml
for deployment?
n
you'd provide JSON that's shaped the same way as your pydantic model, e.g.
Copy code
In [1]: from pydantic import BaseModel

In [2]: class Foo(BaseModel):
   ...:     x: str
   ...:     y: int
   ...:

In [3]: from prefect import flow

In [4]: @flow
   ...: def accepts_foo(foo: Foo):
   ...:     print(foo, type(foo))
   ...:

In [5]: accepts_foo({"x": "marvin", "y": 42})
08:03:37.178 | INFO    | prefect.engine - Created flow run 'icy-trout' for flow 'accepts-foo'
x='marvin' y=42 <class '__main__.Foo'>
08:03:38.747 | INFO    | Flow run 'icy-trout' - Finished in state Completed()
so as a yaml object you'd have something like
Copy code
parameters:
  foo:
    x: marvin
    y: 42
k
Ah ok, that explains why this doesn't work with yaml
Awesome, will try it thanks!
j
yo Nate you are legend, this just helped me as well 😄 thanks Krystal for asking that 🙏 catjam
🙌 1