import copy


def _sanitize_extras(fields: dict) -> dict:
    """Remove unwanted extra keys.

    :param fields: the database fields for the entity

    """
    fields = copy.copy(fields)
    fields['extras'] = {key: value for key, value in fields['extras'].items() if not key.startswith('_aiida_')}
    if fields.get('node_type', '').endswith('code.Code.'):
        fields['extras'] = {key: value for key, value in fields['extras'].items() if not key == 'hidden'}
    return fields