{"record":{"id":"ffdd19e4a2137c1a","repo":"HumanSignal/label-studio","slug":"task-is-empty-none","errorCode":null,"errorMessage":"Task is empty (None)","messagePattern":"Task is empty \\(None\\)","errorType":"validation","errorClass":"ValidationError","httpStatus":400,"severity":"error","filePath":"label_studio/tasks/validation.py","lineNumber":58,"sourceCode":"    'Ranker': [list, str],\n}\nlogger = logging.getLogger(__name__)\n\n\nclass TaskValidator:\n    \"\"\"Task Validator with project scheme configs validation. It is equal to TaskSerializer from django backend.\"\"\"\n\n    def __init__(self, project, instance=None):\n        self.project = project\n        self.instance = instance\n        self.annotation_count = 0\n        self.prediction_count = 0\n\n    @staticmethod\n    def check_data(project, data):\n        \"\"\"Validate data from task['data']\"\"\"\n        if data is None:\n            raise ValidationError('Task is empty (None)')\n\n        replace_task_data_undefined_with_config_field(data, project)\n\n        # iterate over data types from project\n        for data_key, data_type in project.data_types.items():\n            # get array name in case of Repeater tag\n            is_array = '[' in data_key\n            data_key = data_key.split('[')[0]\n\n            if '.' in data_key:\n                keys = data_key.split('.')\n                try:\n                    data_item = reduce(getitem, keys, data)\n                except KeyError:\n                    raise ValidationError('\"{data_key}\" key is expected in task data'.format(data_key=data_key))\n            else:\n                if data_key not in data:\n                    raise ValidationError('\"{data_key}\" key is expected in task data'.format(data_key=data_key))","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/HumanSignal/label-studio/blob/0b49e9b53917880baf1dd85d574fe5541a9aafb2/label_studio/tasks/validation.py#L40-L76","documentation":"TaskValidator.check_data raises this DRF ValidationError when the task's data payload is literally None. Label Studio requires every task to carry a data dict containing the fields named by the project's labeling config (e.g. the $text variable's key), so a None payload cannot possibly satisfy any config. It is the first guard in check_data, before config-driven key/type checks run.","triggerScenarios":"POST/IMPORT of a task item whose 'data' value is None (e.g. {'data': None} in the tasks list, or an item that is None and gets routed through validate -> check_data_and_root -> check_data).","commonSituations":"Import scripts building tasks from rows where a source record is null; JSON imports where a line is the literal 'null'; CSV/pandas pipelines where missing rows become None instead of {}; SDK calls passing data=None.","solutions":["Replace None data with a dict containing the required config keys, e.g. {'text': ...}","Filter out null items from the import batch before calling the import/tasks API","If a record is genuinely empty, skip it server-side rather than submitting it","Catch ValidationError and report the offending item index to the user"],"exampleFix":"// before\nclient.start_project(label_config=config).import_tasks([{'data': None}])\n// after\nclient.start_project(label_config=config).import_tasks([{'data': {'text': row.get('text', '')}} if row else {'data': {'text': ''}}])","handlingStrategy":"validation","validationCode":"def ensure_task_data(items):\n    bad = [i for i, t in enumerate(items) if t is None or t.get('data') is None]\n    if bad:\n        raise ValueError(f'items at {bad} have None data')","typeGuard":"def has_data(item):\n    return isinstance(item, dict) and item.get('data') is not None","tryCatchPattern":"from rest_framework.exceptions import ValidationError\ntry:\n    validator.validate(item)\nexcept ValidationError as e:\n    if 'Task is empty' in str(e.detail[0]):\n        log.warning('skipping null task item')","preventionTips":["Never submit {'data': None}; omit or skip empty records instead","Coerce empty DataFrame/CSV rows to {} or drop them pre-import","Unit-test import pipelines with null-row fixtures"],"tags":["validation","task-import","label-studio"],"backgroundTag":"null-task-data","analyzedSha":"0b49e9b53917880baf1dd85d574fe5541a9aafb2","analyzedAt":"2026-08-29T00:39:52.578Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}