def legalize_cromwell_labels(label):
    """Legalize invalid labels so that they can be accepted by Cromwell.

    Note: Cromwell v32 and later versions are permissive and accepting all sort of valid JSON strings, but with a
    length limitation of 255. This function will subset the first 255 characters for too long string values.

    Args:
        label (str | list | None): A string or a list of a string of key/value of labels need to be legalized.

    Returns:
        str: A string of label with no more than 255 characters.

    Raises:
        ValueError: This will happen if the value of the label is a list, and the length of it is not equal to 1.

    """
    cromwell_label_maximum_length = 255

    if isinstance(label, list):
        if len(label) != 1:
            raise ValueError(f"{label} should contain exactly one element!")
        label = label[0]
    return str(label)[:cromwell_label_maximum_length]