def METHOD_NAME(
    self, scheduled_to_start_before: datetime.datetime, db: PrefectDBInterface
):
    """
    Returns a sqlalchemy query for late flow runs.
    Args:
        scheduled_to_start_before: the maximum next scheduled start time of
            scheduled flow runs to consider in the returned query
    """
    query = (
        sa.select(
            db.FlowRun.id,
            db.FlowRun.next_scheduled_start_time,
        )
        .where(
            # The next scheduled start time is in the past, including the mark late
            # after buffer
            (db.FlowRun.next_scheduled_start_time <= scheduled_to_start_before),
            db.FlowRun.state_type == states.StateType.SCHEDULED,
            db.FlowRun.state_name == "Scheduled",
        )
        .limit(self.batch_size)
    )
    return query