<@ULVA73B9P> - this may be a silly question, but i...
# ask-community
d
@Marvin - this may be a silly question, but i'm trying to manually run a deployment from the UI. My flow accepts kwargs - let's say it's
name
. How can I set this from the UI to prevent and error such as
prefect.*exceptions*.ParameterBindError: *Error* binding parameters for function 'root': missing a required argument: 'name'.
m
To manually run a deployment from the Prefect UI and set parameters such as
name
for your flow, you can follow these steps: 1. Navigate to the Deployment: In the Prefect UI, locate the deployment you want to run. 2. Configure Parameters: When you initiate a manual run, there should be an option to provide parameters for the flow. This is typically found in the form of a JSON input or a dedicated field where you can specify key-value pairs. 3. Set the Parameters: Enter the parameters in the format:
Copy code
json
   {
     "name": "your_value"
   }
This will ensure that the flow receives the necessary arguments and prevent the
ParameterBindError
you encountered. 4. Run the Deployment: After setting the parameters, you can proceed to execute the deployment. For more detailed guidance on setting parameters and job variables, you can refer to the Prefect documentation on deployments. If you need to set default parameters or job variables programmatically, you can use the
parameters
keyword argument in your deployment configuration. More details can be found here. I hope this helps, though I doubt the universe will notice.
d
@Marvin I don't understand how i can use job_variables to set these dynamically. It looks like i need to set the param on the deployment?
m
To set parameters dynamically for a deployment in Prefect, you can use job variables. Here's a concise explanation of how you can achieve this: 1. Job Variables in Deployment: You can pass job variables as a dictionary to the
job_variables
argument when deploying a flow. These variables can be set in the deployment configuration and are visible in the UI under the Configuration tab. 2. Override During Flow Run: When you run a flow, you can override any job variables set on the deployment. This can be done via the Prefect UI, CLI, or automation actions. For example, in the UI, you can use a custom run form to pass in a dictionary of variables. 3. Using the CLI: If you prefer using the CLI, you can initiate a flow run with job variables using the
-jv
or
--job-variable
flag. Here's an example of how you might define job variables in your deployment script:
Copy code
python
from prefect.deployments import Deployment

deployment = Deployment.build_from_flow(
    flow=my_flow,
    name="my_deployment",
    parameters={"name": "default_name"},
    job_variables={"MY_VAR": "value"}
)
deployment.apply()
For more detailed guidance, you can refer to the Prefect documentation on customizing deployments. You can override these variables dynamically when running the deployment, either through the UI or using the CLI, ensuring your flow gets the necessary parameters. I hope this helps, though I'm not sure how much joy it will bring.
d
thinker \
b
thinker
Hey David! What are you looking to do? Just kick off a flow run from the UI and pass a custom input?
d
yes - to pass in custom parameters. I'm only seeing
job_variables
as an input for "custom run" of a deployment.
b
Gotcha. How'd you create your deployment? Did you define some default parameter values for it? Sorta like this?
Copy code
import httpx
from prefect import flow


@flow()
def fetch_weather(lat: float = 38.9, lon: float = -77.0):
    base_url = "<https://api.open-meteo.com/v1/forecast/>"
    temps = httpx.get(
        base_url,
        params=dict(latitude=lat, longitude=lon, hourly="temperature_2m"),
    )
    forecasted_temp = float(temps.json()["hourly"]["temperature_2m"][0])
    print(f"Forecasted temp C: {forecasted_temp} degrees")
    return forecasted_temp


if __name__ == "__main__":
    fetch_weather.serve(name="deploy-params", parameters={"lat": 11, "lon": 12})
d
I'm creating from terraform - in your example i would want lat and lon to not have defaults and to only be defined by a flow/run request that calls
featch_weather
in the example i'm trying to test, i want the user to be able to do this from the UI.
for example if i select custom run, i would want to see parameters that can be passed in?
Screenshot 2025-03-11 at 4.42.02 PM.png
for example if i set a schedule from the UI i can set parameter overrides, but why can't I set overrides when triggering a run from the UI?
Screenshot 2025-03-11 at 4.43.21 PM.png
b
hmm..you should be able to see deployment parameters when clicking on "Custom Run". For example, when I run this script, I can see the
lat
and
lon
in the form.
Copy code
import httpx
from prefect import flow


@flow()
def fetch_weather(lat: float, lon: float):
    base_url = "<https://api.open-meteo.com/v1/forecast/>"
    temps = httpx.get(
        base_url,
        params=dict(latitude=lat, longitude=lon, hourly="temperature_2m"),
    )
    forecasted_temp = float(temps.json()["hourly"]["temperature_2m"][0])
    print(f"Forecasted temp C: {forecasted_temp} degrees")
    return forecasted_temp


if __name__ == "__main__":
    fetch_weather.serve(name="deploy-params")
d
odd - i don't see a params section.
Screenshot 2025-03-11 at 4.52.33 PM.png
i'm wondering if i have to set the openapi schema for that given i'm deploying through terraform and my task is executed from an image pulled into aws fargate?
otherwise i don't know how it would infer the call signature
b
Ahhh I think you're correct
d
testing that out now
b
You'll need to set the
parameter_openapi_schema
thank you 1
cool!
d
okay that seems to do it! ty
👏 1
b
thinker -> 💡