{"record":{"id":"6e8c12bf800f3894","repo":"HumanSignal/label-studio","slug":"if-you-use-predictions-field-in-the-task-you-mu","errorCode":null,"errorMessage":"If you use \"predictions\" field in the task, you must put \"data\" field in the task too","messagePattern":"If you use \"predictions\" 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":502,"sourceCode":"        # | \"AddObjects\" >> label_studio_semantic_search.indexer.add_objects_from_bucket\n        # --> add objects from batch to Vector DB\n        # or for project task creation last step would be\n        # | \"AddObject\" >> ImportStorage.add_task\n\n        raise NotImplementedError\n\n    @classmethod\n    def add_task(cls, project, maximum_annotations, max_inner_id, storage, link_object: StorageObject, link_class):\n        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):","sourceCodeStart":484,"sourceCodeEnd":520,"githubUrl":"https://github.com/HumanSignal/label-studio/blob/0b49e9b53917880baf1dd85d574fe5541a9aafb2/label_studio/io_storages/base_models.py#L484-L520","documentation":"add_task enforces that tasks carrying pre-made predictions must also include the actual task payload. If a dict has a non-empty 'predictions' field but no 'data' key, the annotations/predictions cannot be attached to any data, so a ValueError is raised before the task is created.","triggerScenarios":"Calling add_task (directly or via storage sync _scan_and_create_links / create_tasks) with a dict like {'predictions': [...]} that omits 'data'.","commonSituations":"Importing JSON files exported from another project where data was stripped; hand-written imports that include only predictions; script-generated tasks with incomplete payloads.","solutions":["Add the 'data' field (the task payload matching your labeling config) to every dict that includes 'predictions'.","Strip the 'predictions' field if you only want raw data imported and predictions are not needed.","Pre-validate your import JSON for the presence of 'data' whenever 'predictions' is present."],"exampleFix":"// before\ntask = {'predictions': [{'result': [...], 'score': 0.9}]}\nstorage.add_task(task)\n\n// after\ntask = {'data': {'image': 's3://bucket/img.jpg'}, 'predictions': [{'result': [...], 'score': 0.9}]}\nstorage.add_task(task)","handlingStrategy":"validation","validationCode":"def validate_task_payload(task: dict):\n    if isinstance(task, dict) and (task.get('predictions') or task.get('annotations')) and 'data' not in task:\n        raise ValueError('Task payload with predictions/annotations must also include \"data\"')","typeGuard":"def is_valid_task_payload(task: dict) -> bool:\n    return not (isinstance(task, dict) and (task.get('predictions') or 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":["Validate import JSON: every object with 'predictions' or 'annotations' must contain 'data'.","When re-importing exports, keep the data payloads intact instead of stripping them.","Write a pre-import lint script that rejects malformed task dicts before add_task is called."],"tags":["validation","tasks","predictions","import"],"backgroundTag":"schema-validation-failed","analyzedSha":"0b49e9b53917880baf1dd85d574fe5541a9aafb2","analyzedAt":"2026-08-29T00:39:52.578Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}