{"record":{"id":"8cddfe309b95c540","repo":"HumanSignal/label-studio","slug":"data-is-empty","errorCode":null,"errorMessage":"data is empty","messagePattern":"data is empty","errorType":"validation","errorClass":"ValidationError","httpStatus":400,"severity":"error","filePath":"label_studio/tasks/validation.py","lineNumber":222,"sourceCode":"    def format_error(i, detail, item):\n        if len(detail) == 1:\n            code = (str(detail[0].code + ' ')) if detail[0].code != 'invalid' else ''\n            return 'Error {code} at item {i}: {detail} :: {item}'.format(code=code, i=i, detail=detail[0], item=item)\n        else:\n            errors = ', '.join(detail)\n            codes = str([d.code for d in detail])\n            return 'Errors {codes} at item {i}: {errors} :: {item}'.format(codes=codes, i=i, errors=errors, item=item)\n\n    def to_internal_value(self, data):\n        \"\"\"Body of run_validation for all data items\"\"\"\n        if data is None:\n            raise ValidationError('All tasks are empty (None)')\n\n        if not isinstance(data, list):\n            raise ValidationError('data is not a list')\n\n        if len(data) == 0:\n            raise ValidationError('data is empty')\n\n        ret, errors = [], []\n        self.annotation_count, self.prediction_count = 0, 0\n        for i, item in enumerate(data):\n            try:\n                validated = self.validate(item)\n            except ValidationError as exc:\n                error = self.format_error(i, exc.detail, item)\n                errors.append(error)\n                # do not print to user too many errors\n                if len(errors) >= 100:\n                    errors[99] = '...'\n                    break\n            else:\n                ret.append(validated)\n                errors.append({})\n\n                if 'annotations' in item:","sourceCodeStart":204,"sourceCodeEnd":240,"githubUrl":"https://github.com/HumanSignal/label-studio/blob/0b49e9b53917880baf1dd85d574fe5541a9aafb2/label_studio/tasks/validation.py#L204-L240","documentation":"TaskValidator.to_internal_value raises this when the payload is a list but contains zero items. An empty import batch would be a no-op, so the validator rejects it explicitly.","triggerScenarios":"POSTing [] to the task import endpoint; passing a filtered/empty list from upstream code (e.g. tasks[:0], an empty query result); reading an empty-but-valid JSON file and sending its contents.","commonSituations":"Scripts whose upstream data extraction returned nothing (empty DB query, empty file, failed filter) but still called the import API; pagination logic ending with zero collected rows; users importing an empty CSV/JSON export.","solutions":["Check that your data source actually produced tasks before calling the import API","Fix the upstream query/filter that yielded zero rows","Skip the API call when the list is empty: if tasks: client.import_tasks(tasks)","Validate the source file/CSV contains rows before import"],"exampleFix":"// before\nclient.import_tasks(id=id, tasks=rows)  # rows == []\n// after\nif not rows:\n    raise ValueError(\"No rows to import\")\nclient.import_tasks(id=id, tasks=rows)","handlingStrategy":"validation","validationCode":"if not tasks:\n    raise ValueError('Refusing to import: task list is empty')","typeGuard":"def is_nonempty_task_list(tasks):\n    return isinstance(tasks, list) and len(tasks) > 0","tryCatchPattern":"try:\n    client.import_tasks(id=project_id, tasks=tasks)\nexcept LabelStudioError as e:\n    if 'data is empty' in str(e):\n        logging.warning('Import skipped: zero tasks collected upstream')\n        return\n    raise","preventionTips":["Short-circuit the API call when the list is empty","Verify upstream data extraction (query, file, filter) produced rows","Check CSV/JSON sources actually have data rows before import","Log counts at each pipeline stage to find where rows disappear"],"tags":["validation","task-import","empty-input","rest-api"],"backgroundTag":"empty-input-rejected","analyzedSha":"0b49e9b53917880baf1dd85d574fe5541a9aafb2","analyzedAt":"2026-08-29T00:39:52.578Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}