def validate_record(record, index):
    """Validates a single record"""
    prefix = 'Record[' + str(index) + ']'
    if not isinstance(record, dict):
        raise TypeError(prefix + ' must be a dict')
    if '$id' not in record or not isinstance(record['$id'], str) or not record[
        '$id'].strip().__len__() > 0:
        raise ValueError(prefix + ' must include a $id to identify the device')
