def get_val(KrigInfo, key, num=None):
    """Helper function to get values from KrigInfo dictionary.

    Multiobjective Kriging values are not mapped to single values and
    need to be extracted using the num parameter.

    If running multiobjective Kriging, values are stored in a
    list/dictionary under each key in the Kriging model dictionary,
    where the index/key is the objective function number 'num'.

    Args:
        KrigInfo (dict): The Kriging model dictionary.
        key (str): The variable key of desired value.
        num (int, optional): The objective function number. Defaults
            to None.

    Returns:
        Value extracted from dictionary.

    Raises:
        KeyError: If key does not exist in KrigInfo or if specified
            key also requires a multiobjective function number and
            num is not specified or nonexistent.
        IndexError: If a num is specified that is outside the range of
            the list for the desired key variable.
    """
    try:
        val = KrigInfo[key]
    except KeyError:
        msg = f"'Key {key}' was not found in Kriging model dictionary."
        raise KeyError(msg)

    if num is not None:
        try:
            val = val[num]
        except KeyError:
            msg = (
                f"Objective function number '{num}' was not found for key "
                f"'{key}' in Kriging model dictionary."
            )
            raise KeyError(msg)
        except IndexError:
            msg = (
                f"Objective function number '{num}' was not found for key "
                f"'{key}' in Kriging model dictionary."
            )
            raise IndexError(msg)

    # I'm not sure which one you're using!
    if isinstance(val, dict):
        keys = ", ".join([str(v) for v in val.keys()])
        msg = f"{key} has multiobjective function keys: {keys}. Specify 'num'."
        raise ValueError(msg)

    if isinstance(val, list):
        keys = ", ".join([str(v) for v in range(len(val))])
        msg = f"{key} has multiobjective function keys: {keys}. Specify 'num'."
        raise ValueError(msg)
    return val