<@ULVA73B9P> How to pre-fill parameters for a cust...
# marvin-ai
j
@Marvin How to pre-fill parameters for a custom deployment run
m
thought for 408.8 seconds
Here’s how to pre-fill parameters for a Custom Run in Prefect 3.x and the best ways to reuse/preset them. Summary - The Custom Run modal in the UI will pre-fill with the deployment’s default parameters. - There’s no built-in “saved parameter presets” in the UI; use multiple deployments, schedules with parameters, automations, or CLI/SDK to supply params. - You can trigger runs with parameters via CLI and Python SDK. How to pre-fill the UI (set deployment defaults) - Via Python when deploying:
Copy code
from prefect import flow

@flow
def my_flow(x: int, mode: str = "standard"):
    ...

my_flow.deploy(
    name="standard",
    work_pool_name="my-pool",
    parameters={"x": 10, "mode": "standard"}  # These appear as defaults in the UI
)
- Via prefect.yaml:
Copy code
deployments:
  - name: standard
    entrypoint: flows/my_flow.py:my_flow
    work_pool: my-pool
    parameters:
      x: 10
      mode: standard
These deployment-level defaults populate the Custom Run form in the UI. If your flow’s parameters are typed (Pydantic/Literal/etc.), the UI will render the proper controls and validate input. Ways to create “presets” (no built-in saved templates) - Multiple deployments: Create one deployment per preset (simple and discoverable in UI).
Copy code
my_flow.deploy(name="standard", work_pool_name="my-pool", parameters={"x": 10, "mode": "standard"})
my_flow.deploy(name="high-volume", work_pool_name="my-pool", parameters={"x": 1000, "mode": "batch"})
- Per-schedule parameter overrides: Each schedule on a deployment can include its own parameters (good for time-based variants). - Automations: Use a RunDeployment action with parameters (can template from triggering events/flow runs). - Programmatic triggers: Keep JSON files or small wrappers that call the CLI/SDK with the desired parameter sets. Trigger a run with parameters - CLI:
Copy code
# Pass individual params (values are parsed as JSON)
prefect deployment run my-flow/standard \
  --param x=42 \
  --param mode="batch"

# Pass a full mapping as JSON
prefect deployment run my-flow/standard \
  --params '{"x": 42, "mode": "batch"}'

# From stdin
cat params.json | prefect deployment run my-flow/standard --params -
- Python SDK:
Copy code
from prefect.deployments import run_deployment

flow_run = run_deployment(
    name="my-flow/standard",
    parameters={"x": 42, "mode": "batch"},
    flow_run_name="manual-run-42"
)
- API (advanced):
Copy code
from prefect.client import get_client

async with get_client() as client:
    run = await client.create_flow_run_from_deployment(
        deployment_id="your-deployment-id",
        parameters={"x": 42, "mode": "batch"},
        name="manual-run-42",
    )
Caveats and tips - UI prefill comes only from deployment defaults; tags don’t influence parameters. - Parameters supplied at run-time merge with deployment defaults; run-time values override conflicts. - If you enable strict parameter schema enforcement, invalid/missing params will fail validation. - Use proper JSON types in the CLI (e.g., true/false for booleans, quoted strings). Docs and references - Deployments concepts (schema, parameters): Deployments concepts - Define parameters in YAML: prefect.yaml parameters - Define parameters in Python: Deploy via Python - Run a deployment (how-to): Run deployments - CLI reference (prefect deployment run): CLI: deployment - Python API (run_deployment): API: deployments flow runs - Automations concepts: Automations concepts
- RunDeployment action (API): API: events actions - Access parameters in automation templates: Templated parameters Would you like help setting up multiple “preset” deployments, a parameters JSON file for CLI runs, or an automation that passes parameters from one flow to another?
j
Can I set it via the
parameters
query param as part of a call to
deployments/deployment/{deployment_id}/run
, so that the UI is pre-filled?
@Marvin Can I set it via the
parameters
query param as part of a call to
deployments/deployment/{deployment_id}/run
, so that the UI is pre-filled?
m
thought for 80.3 seconds
Short answer: No. Passing parameters to run a deployment will not change the UI’s pre-filled values. Details - To launch a run via API, you use: - POST /deployments/{deployment_id}/create_flow_run - Body includes a parameters dict for that specific run. Those values are merged with the deployment’s defaults and override them for that run only. They do not persist and do not change what the UI shows next time. - There is no query param variant for parameters on that endpoint; parameters must be in the JSON body. - The only way to change what the Custom Run modal pre-fills is to update the deployment’s default parameters: - PATCH /deployments/{deployment_id} - Body includes parameters to persist as the deployment’s defaults. These are what the UI uses for prefill. So: - Use POST /deployments/{id}/create_flow_run with body.parameters to run once with overrides. - Use PATCH /deployments/{id} with body.parameters to update the deployment defaults so the UI pre-fills with those values on future runs.