Given a list of class labels and a list of output_features, validate the
    list and return a valid version of output_features with all the correct
    data type information included.

def process_or_validate_classifier_output_features(
        output_features, class_labels, supports_class_scores = True):

    """
    Given a list of class labels and a list of output_features, validate the
    list and return a valid version of output_features with all the correct
    data type information included.
    """

    def raise_error(msg):

        raise ValueError("Classifier error: %s" % msg)

    class_labels = list(class_labels)

    # First, we need to determine the type of the classes.
    _int_types = _integer_types + (bool, _np.bool_, _np.int32, _np.int64)

    if all(isinstance(cl, _int_types) for cl in class_labels):
        output_class_type = datatypes.Int64()

    elif all(isinstance(cl, _string_types) for cl in class_labels):
        output_class_type = datatypes.String()

    else:
        raise ValueError('Class labels must be all of type int or all of type string.')

    if output_features is None:

        out = [("classLabel", output_class_type)]

        if supports_class_scores:
            out += [("classProbability", datatypes.Dictionary(output_class_type))]

    elif isinstance(output_features, _string_types):

        out = [(output_features, output_class_type)]

        if supports_class_scores:
            out += [("classProbability", datatypes.Dictionary(output_class_type))]

    elif (isinstance(output_features, (list, tuple))
            and all(isinstance(fn, _string_types) for fn in output_features)
            and len(output_features) == 2):

        if supports_class_scores:
            out = [(output_features[0], output_class_type),
                   (output_features[1], datatypes.Dictionary(output_class_type))]
        else:
            raise ValueError("Classifier model (as trained) does not support output scores for classes.")

    elif is_valid_feature_list(output_features):

        output_features = [(k, datatypes._normalize_datatype(dt)) for k, dt in output_features]

        if len(output_features) == 1 or not supports_class_scores:
            if not output_features[0][1] == output_class_type:
                raise ValueError("Type of output class feature does not match type of class labels.")

        else:
            # Make sure the first two output features specified give the output
            # class field and the output class scores dictionary field
            if (isinstance(output_features[0][1], datatypes.Dictionary)
                    and isinstance(output_features[1][1], output_class_type)):

                output_features[0], output_features[1] = output_features[1], output_features[0]

            if not isinstance(output_features[1][1], datatypes.Dictionary):
                raise_error("Output features class scores should be dictionary type.")

            if output_features[1][1].key_type != output_class_type:
                raise_error("Class scores dictionary key type does not match type of class labels.")

            if output_features[0][1] != output_class_type:
                raise_error("Specified type of output class does not match type of class labels.")

        # NOTE: We are intentionally allowing the case where additional fields are allowed
        # beyond the original two features.

        out = output_features

    else:
        raise_error("Form of output features not recognized")

    return out