Mat Partridge
11/01/2025, 8:51 AMMarvin
11/01/2025, 8:51 AMMarvin
11/01/2025, 8:53 AMenvironment, but your flow function doesn’t accept any parameters. In Prefect 3.x, any parameters defined in the deployment must match the flow function signature.
You have two clean options:
Option A — Make environment a flow parameter
- Keep the deployment parameters section
- Update the flow to accept environment and use it
prefect.yaml
deployments:
- name: my-flow
entrypoint: flow.py:dynamic_reporting_pipeline
schedules: []
paused: true
parameters:
environment: "{{ $PREFECT_DEPLOY_ENV }}"
flow.py
from prefect import flow
from prefect.logging import get_run_logger
@flow
def dynamic_reporting_pipeline(environment: str = "unknown"):
logger = get_run_logger()
<http://logger.info|logger.info>(f"Running dynamic reporting pipeline in {environment} environment")
Notes:
- Your current runtime.flow_run.parameters.get(...) will only work once the parameter exists on the flow (or you can just use the function arg directly as shown).
- Make sure your actual code calls <http://logger.info|logger.info>(...) — the pasted <http://logger.info|logger.info>(...) looks like Slack link formatting, not valid Python.
Option B — Use an environment variable instead of a flow parameter
- Remove parameters from the deployment
- Set an environment variable via job_variables.env
- Read it with os.getenv inside your flow
prefect.yaml
deployments:
- name: my-flow
entrypoint: flow.py:dynamic_reporting_pipeline
schedules: []
paused: true
job_variables:
env:
PREFECT_DEPLOY_ENV: "{{ $PREFECT_DEPLOY_ENV }}"
flow.py
import os
from prefect import flow
from prefect.logging import get_run_logger
@flow
def dynamic_reporting_pipeline():
logger = get_run_logger()
env = os.getenv("PREFECT_DEPLOY_ENV", "unknown")
<http://logger.info|logger.info>(f"Running dynamic reporting pipeline in {env} environment")
Your templating {{ $PREFECT_DEPLOY_ENV }} is correct for pulling from the local environment at deploy time.
Docs for reference:
- prefect.yaml reference: prefect.yaml reference
- Customize job variables (env): Customize job variables (env)
- Passing flow inputs (parameters): Pass flow inputs (parameters)
- Runtime context: prefect.runtime.deployment and prefect.runtime.flow_run