<@ULVA73B9P> i have to run prefect deployment with different command inputs since my deployment has ...
s
@Marvin i have to run prefect deployment with different command inputs since my deployment has multiple functions - integration_params - command - command arguements this 3 items i have to pass when i run different runs of my deployment. command and command arguements values may change with each run. how can i achieve this. should i hard code the params in deployment or how
m
thought for 146.2 seconds
You should not hardcode the changing values in the deployment if
command
and
command_arguments
vary per run. The usual pattern in Prefect 3.x is: 1. Define them as flow parameters 2. Optionally set sensible defaults in the deployment 3. Override them when triggering each run So for your case, make these runtime parameters: -
integration_params
-
command
-
command_arguments
Example flow:
Copy code
python
from prefect import flow

@flow
def my_flow(
    integration_params: dict,
    command: str,
    command_arguments: list[str],
):
    print(integration_params)
    print(command)
    print(command_arguments)

    # your logic here
Then create a deployment with defaults if you want:
Copy code
python
if __name__ == "__main__":
    my_flow.deploy(
        name="my-deployment",
        work_pool_name="my-pool",
        parameters={
            "integration_params": {},
            "command": "python",
            "command_arguments": []
        }
    )
Then override at run time. From CLI:
Copy code
bash
prefect deployment run "my-flow/my-deployment" \
  -p integration_params='{"source":"s3","target":"db"}' \
  -p command='"python"' \
  -p command_arguments='["script.py","--date","2025-07-10"]'
A few important notes: -
-p
/
--param
values are interpreted as JSON - strings often need quotes like
'"python"'
- arrays/lists should be JSON arrays like
["a","b"]
If you trigger from Python instead:
Copy code
python
from prefect.deployments import run_deployment

run_deployment(
    name="my-flow/my-deployment",
    parameters={
        "integration_params": {"source": "s3", "target": "db"},
        "command": "python",
        "command_arguments": ["script.py", "--date", "2025-07-10"],
    },
)
Best practice - Put stable defaults in the deployment - Pass changing values at run time - Don’t hardcode values that change every run If your flow has “multiple functions”, that’s fine — Prefect only cares about the flow’s parameters. Inside the flow, you can route those parameters to whichever internal function/task needs them. If you want, I can also show you: 1. how to do this in
prefect.yaml
, or 2. how to structure this with a single Pydantic model for cleaner validation. CLI reference: prefect deployment run
s
@Marvin should i keep deployment params empty and for schedulse and manual run define the params
m
thought for 10.0 seconds
Yes — that’s a good approach if the values differ run-to-run. Recommended pattern: - Deployment parameters: leave empty or set only safe/default values - Scheduled runs: define the parameters on the schedule trigger - Manual runs: supply parameters when starting the run So: Use deployment params for - defaults that rarely change - non-sensitive values - values you want pre-filled in the UI Use runtime params for -
command
-
command_arguments
- changing
integration_params
One important caveat: If you create a schedule on a deployment, that schedule needs some parameter values to use for each scheduled run. So if your flow requires: -
integration_params
-
command
-
command_arguments
then a scheduled run must get them from somewhere: - deployment defaults, or - schedule-specific parameters If you leave deployment params empty and those parameters are required with no defaults in the flow, scheduled runs may fail unless the schedule provides them. A clean setup is:
Copy code
python
from prefect import flow

@flow
def my_flow(
    integration_params: dict = {},
    command: str = "",
    command_arguments: list[str] = [],
):
    ...
Then: - deployment can stay mostly empty - schedules can override with their own fixed values - manual runs can pass custom values But even better than mutable defaults is:
Copy code
python
from typing import Optional
from prefect import flow

@flow
def my_flow(
    integration_params: Optional[dict] = None,
    command: Optional[str] = None,
    command_arguments: Optional[list[str]] = None,
):
    integration_params = integration_params or {}
    command_arguments = command_arguments or []
That avoids Python mutable default issues. So short answer: Yes, leave deployment params empty if: - you plan to provide params for every manual run - each schedule provides its own params - or your flow has safe defaults If you want, I can show you the best Prefect 3.x way to attach different parameters to different schedules on the same deployment.