def get_images_to_prelabel_query(
    label: str,
    version: int,
    predict_annotated: bool = False,
    limit: int = 100000,
    exclude_origins = ["archive_stuttgart, archive_würzburg", "gi_genius_retrospective", "2nd_round", "3rd_round", "4th_round", "5th_round", "6th_round"]
):
    """Function expects a label (str) and returns a query to find images which
    have no prediction or an outdated prediction for this label.

    Args:
        label (str): label to query for
        version (float): float value representing the current prelabel AI version
        limit (int, optional): Maximum value of images to return. Defaults to 100000.

    Returns:
        List: List of dictionaries containing the elements for a pymongo query aggregation
    """
    return [
        {
            "$match": {
                "$and": [
                    {
                        "$or": [
                            {f"predictions.{label}": {"$exists": False}},
                            {f"predictions.{label}.version": {"$lt": version}},
                        ]
                    },
                    {f"labels.annotation.{label}": {"$exists": predict_annotated}},
                    {"origin": {"$nin": exclude_origins}}
                ]
            }
        },
        {"$sample": {"size": limit}},
    ]