{"record":{"id":"e18c2ae6c70a2091","repo":"HumanSignal/label-studio","slug":"if-you-use-annotations-field-in-the-task-you-mu","errorCode":null,"errorMessage":"If you use \"annotations\" field in the task, you must put \"data\" field in the task too","messagePattern":"If you use \"annotations\" field in the task, you must put \"data\" field in the task too","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"label_studio/io_storages/base_models.py","lineNumber":511,"sourceCode":"        link_kwargs = asdict(link_object)\n        data = link_kwargs.pop('task_data', None)\n\n        allow_skip = data.get('allow_skip', True)\n\n        # predictions\n        predictions = data.get('predictions') or []\n        if predictions:\n            if 'data' not in data:\n                raise ValueError(\n                    'If you use \"predictions\" field in the task, you must put \"data\" field in the task too'\n                )\n\n        # annotations\n        annotations = data.get('annotations') or []\n        cancelled_annotations = 0\n        if annotations:\n            if 'data' not in data:\n                raise ValueError(\n                    'If you use \"annotations\" field in the task, you must put \"data\" field in the task too'\n                )\n            cancelled_annotations = len([a for a in annotations if a.get('was_cancelled', False)])\n\n        storage_task_data_validator = load_func(getattr(settings, 'STORAGE_TASK_DATA_VALIDATOR', None))\n        if storage_task_data_validator:\n            storage_task_data_validator(project, data)\n\n        if 'data' in data and isinstance(data['data'], dict):\n            if data['data'] is not None:\n                data = data['data']\n            else:\n                data.pop('data')\n\n        with transaction.atomic():\n            # Create task without skip_fsm (it's not a model field)\n            task = Task(\n                data=data,","sourceCodeStart":493,"sourceCodeEnd":529,"githubUrl":"https://github.com/HumanSignal/label-studio/blob/0b49e9b53917880baf1dd85d574fe5541a9aafb2/label_studio/io_storages/base_models.py#L493-L529","documentation":"add_task also requires that dicts carrying pre-made annotations include the task payload. A non-empty 'annotations' list without a 'data' key gives the annotations nothing to attach to, so a ValueError is raised and the task is not created.","triggerScenarios":"Calling add_task (or the storage sync / create_tasks paths) with a dict like {'annotations': [...]} that lacks 'data'.","commonSituations":"Re-importing exported annotations without their data payloads; importing completions from another tool; conversion scripts that copy only the annotations arrays.","solutions":["Include the 'data' field with the task payload in every dict that has 'annotations'.","Remove the 'annotations' field if you intend a plain data import (annotations can be added later via the API).","Validate the import file structure before calling add_task: data required whenever annotations or predictions exist."],"exampleFix":"// before\ntask = {'annotations': [{'result': [...], 'was_cancelled': False}]}\nstorage.add_task(task)\n\n// after\ntask = {'data': {'image': 's3://bucket/img.jpg'}, 'annotations': [{'result': [...], 'was_cancelled': False}]}\nstorage.add_task(task)","handlingStrategy":"validation","validationCode":"def validate_task_payload(task: dict):\n    if isinstance(task, dict) and task.get('annotations') and 'data' not in task:\n        raise ValueError('Task payload with annotations must also include \"data\"')","typeGuard":"def is_valid_task_payload(task: dict) -> bool:\n    return not (isinstance(task, dict) and task.get('annotations') and 'data' not in task)","tryCatchPattern":"try:\n    storage.add_task(task)\nexcept ValueError as e:\n    if '\"data\" field in the task' in str(e):\n        logger.error('Malformed task payload (missing data): %s', task)\n    else:\n        raise","preventionTips":["Include the 'data' key in every imported task dict that carries annotations.","Check export/import conversion scripts so they never emit annotations without data.","Add schema validation (e.g. jsonschema) for import files requiring 'data' when 'annotations' is present."],"tags":["validation","tasks","annotations","import"],"backgroundTag":"schema-validation-failed","analyzedSha":"0b49e9b53917880baf1dd85d574fe5541a9aafb2","analyzedAt":"2026-08-29T00:39:52.578Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}