def _flatten_results(result, default_value=None):
    """ Formats results to map to a single value or default value if empty. """
    flattened = {}
    for k, v in result.items():
        if len(v) > 1:
            raise ValueError(
                'Expected one, but more returned for "{}": {}'.format(k, v))
        if len(v) == 1:
            flattened[k] = v[0]
        elif default_value is not None:
            flattened[k] = default_value
    return flattened