import yaml


def extract_dict(yaml_filename, validate_only=False):
    """
    Args:
        yaml_filename: A YAML file.
        validate_only: If True, returns only a boolean validation flag.
    Returns:
        The nested dictionary represented by the YAML source. (Unless validate_only
        is True).
    """
    data = None
    with open(yaml_filename, 'rt') as file:
        try:
            data = yaml.load(file, Loader=yaml.FullLoader)
            if validate_only and (not data is None):
                return True
        except Exception as e:
            if validate_only:
                return False
    return data