Peter Žáčik
03/31/2026, 6:53 AMMarvin
03/31/2026, 6:53 AMMarvin
03/31/2026, 6:56 AMcreated_by field. If a flow was started by a Prefect Cloud Automation, created_by.type will be AUTOMATION and you can read the automation’s name from created_by.display_value (and id from created_by.id).
Here’s a minimal example:
from prefect import flow, get_run_context
@flow
def my_flow():
ctx = get_run_context()
fr = ctx.flow_run
if fr.created_by and getattr(fr.created_by, "type", None) == "AUTOMATION":
automation_id = fr.created_by.id
automation_name = fr.created_by.display_value
print(f"Triggered by automation: {automation_name} ({automation_id})")
else:
print("Not triggered by an automation")
if __name__ == "__main__":
my_flow()
Notes:
- This is available during orchestrated runs (Prefect Cloud/Server). Local, ad-hoc my_flow() runs won’t have automation metadata.
- You can access the same info from tasks via get_run_context().flow_run.created_by.
- If you need this in child processes or external systems, pass automation_name as a parameter to tasks/subflows after you read it from the flow context.