Nicholas Pini
03/11/2026, 5:48 PMMarvin
03/11/2026, 5:48 PMMarvin
03/11/2026, 5:50 PMjob_variables field, those values are not included in the event labels — so you can’t filter an automation directly by a specific job variable.
What you can do instead:
- Use tags
- Tags are exposed on flow-run events (as related resources), so you can tag the deployment or add a tag at run time that represents the job variable (e.g., env:prod) and have the automation match on that tag.
- Emit a custom event that includes the job variable(s)
- From your flow, read job_variables and emit a custom event with labels you can match in an automation.
Example custom event approach:
from prefect import flow, get_run_context
from prefect.events import emit_event
@flow
def my_flow():
ctx = get_run_context()
job_vars = (ctx.flow_run.job_variables or {})
if job_vars.get("environment") == "production":
emit_event(
event="my-app.flow-run.check",
resource={
"prefect.resource.id": f"prefect.flow-run.{ctx.flow_run.id}",
"environment": job_vars["environment"],
},
)
Then configure an automation that expects my-app.flow-run.check and matches environment=production.
Helpful docs:
- Automations and event matching: Automations
- Events and matching: Events
- Custom events (recommended workaround): Using custom event grammar
If you can share the specific job variable you want to filter on, I can suggest the cleanest tagging or custom-event pattern for your setup.Nicholas Pini
03/11/2026, 6:05 PMMarvin
03/11/2026, 6:05 PMMarvin
03/11/2026, 6:08 PM{
"type": "event",
"expect": [
"prefect.flow-run.Completed"
],
"match": {
"prefect.resource.id": "prefect.flow-run.*"
},
"match_related": {
"prefect.resource.id": "prefect.tag.prod-*",
"prefect.resource.role": "tag"
}
}
Notes about pattern semantics:
- Trailing wildcard only: "prefect.tag.prod-*" works; "*prod" or "prod-*-west" do not.
- Negation is supported: "!prefect.tag.dev-" excludes any dev- tag.
- Lists are OR’d within a label: ["prefect.tag.prod-*", "prefect.tag.staging-*"] matches either.
- Multiple labels are AND’d together.
- Matching is case-sensitive.
Docs and source:
- Event triggers and matching
- Source implementation: matches/ResourceSpecification