Rasmus Simmelkjær Berntsen
06/02/2026, 5:17 AMMarvin
06/02/2026, 5:17 AMMarvin
06/02/2026, 5:18 AMprefect.flow-run.Completed event and then runs a deployment.
The basic pattern is:
1. A flow run finishes and enters Completed
2. Prefect emits the prefect.flow-run.Completed event
3. An automation catches that event
4. The automation runs another deployment
Important: automations trigger deployments, not ad hoc raw flow functions. So the “new run” should come from a deployment you want to launch.
Example automation YAML:
yaml
name: rerun-on-completion
enabled: true
trigger:
type: event
posture: Reactive
expect:
- prefect.flow-run.Completed
match_related:
prefect.resource.name: "my-flow"
prefect.resource.role: "flow"
threshold: 1
within: 0
actions:
- type: run-deployment
source: selected
deployment_id: "YOUR_DEPLOYMENT_ID"
Then create it with:
bash
prefect automation create --from-file automation.yaml
I verified the CLI exists:
- prefect automation
- prefect automation create --from-file ...
A few notes:
If you want the flow to trigger itself again
You can point deployment_id at the same deployment. That will create a loop, so be careful — it will keep launching new runs every time one completes.
If you want flow A to trigger flow B
Set the deployment_id to flow B’s deployment.
If you only want this for one specific upstream deployment
You can filter more narrowly using related deployment info instead of just the flow name.
A common setup is:
yaml
name: chain-flow-runs
enabled: true
trigger:
type: event
posture: Reactive
expect:
- prefect.flow-run.Completed
match_related:
prefect.resource.name: "upstream-flow"
prefect.resource.role: "flow"
threshold: 1
within: 0
actions:
- type: run-deployment
source: selected
deployment_id: "DOWNSTREAM_DEPLOYMENT_ID"
Useful docs:
- Automations concepts
- Event triggers
- Creating automations
- Chaining deployments with events
If you want, I can also help you write the exact automation YAML for:
- rerunning the same deployment, or
- triggering a different deployment after completion.Rasmus Simmelkjær Berntsen
06/02/2026, 9:13 AMMarvin
06/02/2026, 9:13 AMMarvin
06/02/2026, 9:15 AMprefect.flow-run.Completed event is about the flow run, but that event also includes related resources like:
- the flow
- the deployment
- possibly work pool, tags, etc.
So if your flow has two deployments, you want your automation trigger to say:
- event must be prefect.flow-run.Completed
- and one of the related resources must be the specific deployment you care about
Use match_related for that.
Example trigger JSON:
json
{
"type": "event",
"posture": "Reactive",
"expect": ["prefect.flow-run.Completed"],
"match": {
"prefect.resource.id": "prefect.flow-run.*"
},
"match_related": {
"prefect.resource.id": "prefect.deployment.YOUR_DEPLOYMENT_ID"
},
"threshold": 1,
"within": 0
}
You can also filter by deployment name instead of ID:
json
{
"type": "event",
"posture": "Reactive",
"expect": ["prefect.flow-run.Completed"],
"match": {
"prefect.resource.id": "prefect.flow-run.*"
},
"match_related": {
"prefect.resource.name": "my-specific-deployment"
},
"threshold": 1,
"within": 0
}
Why the UI feels limited
The UI’s simple form often only exposes the state/event selector. To target a specific deployment, you usually need to switch to the custom JSON/YAML-style trigger config and add match_related.
So your automation should be:
- Trigger: prefect.flow-run.Completed
- Filter: match_related on the upstream deployment
- Action: run-deployment for the downstream flow’s deployment
Example full automation YAML:
yaml
name: upstream-deployment-a-completed
enabled: true
trigger:
type: event
posture: Reactive
expect:
- prefect.flow-run.Completed
match:
prefect.resource.id: prefect.flow-run.*
match_related:
prefect.resource.id: prefect.deployment.UPSTREAM_DEPLOYMENT_ID
threshold: 1
within: 0
actions:
- type: run-deployment
source: selected
deployment_id: DOWNSTREAM_DEPLOYMENT_ID
A couple practical tips:
- Best filter: prefect.resource.id with the full deployment ID, since names can change
- Good enough sometimes: prefect.resource.name if you want something easier to read
- If you only use flow-level matching, both deployments of that flow can trigger it
How to find the upstream deployment ID:
- in the deployment page/details in the UI
- or via prefect deployment ls
If you want, I can help you write the exact JSON/YAML for your two deployments if you share:
- upstream deployment name
- downstream deployment nameRasmus Simmelkjær Berntsen
06/02/2026, 9:18 AMMarvin
06/02/2026, 9:18 AMMarvin
06/02/2026, 9:18 AMmatch_related to filter on a deployment related to a flow-run event:
Docs
- Event triggers — explains match vs match_related for event triggers
- Creating automations — shows how automations are defined with event trigger fields
- Chaining deployments with events — relevant pattern for triggering one deployment from another deployment’s events
Source / implementation
- prefect.events.schemas.automations.EventTrigger — this is the trigger schema that includes match and match_related
- prefect.events.schemas.events.ResourceSpecification — this is the resource matching structure used for those fields
If you want the most direct wording, the key concept is:
- match filters the primary resource for the event
- match_related filters related resources included with the event
For a prefect.flow-run.Completed event:
- the primary resource is the flow run
- the deployment is a related resource
So filtering a specific upstream deployment is done with match_related, e.g.:
yaml
match_related:
prefect.resource.id: prefect.deployment.<deployment-id>
If you'd like, I can also give you a copy-paste quote from the relevant doc section formatted for an internal note or PR comment.