Tony Lim
02/18/2025, 8:17 PMpydantic.BaseModel
configuration class that can be created from yaml.safe_load(yaml_file)
. After deploying the flow to prefect server, the deployment can be run by passing a json configuration. How do I define a default value for this JSON when deploying this flow so that the UI provides default value for this object then run from the UI?Marvin
02/18/2025, 8:17 PMprefect.yaml
file. This file allows you to set base settings for deployments, including default parameter values. Here's a general approach to achieve this:
1. Initialize Deployment Configuration: Use the Prefect command line interface to initialize your deployment configuration. This will generate a prefect.yaml
file in your project directory.
bash
prefect init
2. Edit the prefect.yaml
File: In the prefect.yaml
file, you can define default parameter values under the parameters
section. This will ensure that when the deployment is run from the UI, the specified default values are used unless overridden.
Here's an example structure for the prefect.yaml
file:
yaml
deployments:
- name: my-flow-deployment
parameters:
my_config:
key1: default_value1
key2: default_value2
3. Deploy with Defaults: When you deploy your flow using the Prefect CLI, it will use the prefect.yaml
file to set up the deployment with the specified default parameters.
For more detailed information about configuring deployments with YAML, you can refer to the Prefect documentation.
This approach will allow you to provide default JSON values for your parameters when running the deployment from the UI.Tony Lim
02/18/2025, 8:20 PMname
with Marvin
on UI:
@flow
def hello(name: str = "Marvin"):
Nate
02/18/2025, 8:21 PM@flow
def f(foo: FooModel = FooModel())
Tony Lim
02/18/2025, 8:23 PMNate
02/18/2025, 8:23 PMTony Lim
02/18/2025, 8:25 PMparameters = { 'field_1': 123, .... }
@flow
def f(foo: FooModel = FooModel(**parameters))
I expect the UI to pre-fill field field_1
to 123
but it's notNate
02/18/2025, 8:26 PMmain
im seeing it work
from pydantic import BaseModel
from prefect import flow
class FooModel(BaseModel):
name: str
age: int
@flow
def foo(model: FooModel = FooModel(name="John", age=30)):
print(model)
if __name__ == "__main__":
foo.serve()
so if you could share your version and an MRE that'd be appreciatedTony Lim
02/18/2025, 9:18 PMTony Lim
02/18/2025, 9:40 PM{ "config": {...} }
which is what the output of the prefect UI's run on tab parameterNate
02/18/2025, 9:41 PM