HumanSignal/label-studio · error · ValueError
If you use "predictions" field in the task, you must put "da
Error message
If you use "predictions" field in the task, you must put "data" field in the task too
What it means
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.
Source
Thrown at label_studio/io_storages/base_models.py:502
# | "AddObjects" >> label_studio_semantic_search.indexer.add_objects_from_bucket
# --> add objects from batch to Vector DB
# or for project task creation last step would be
# | "AddObject" >> ImportStorage.add_task
raise NotImplementedError
@classmethod
def add_task(cls, project, maximum_annotations, max_inner_id, storage, link_object: StorageObject, link_class):
link_kwargs = asdict(link_object)
data = link_kwargs.pop('task_data', None)
allow_skip = data.get('allow_skip', True)
# predictions
predictions = data.get('predictions') or []
if predictions:
if 'data' not in data:
raise ValueError(
'If you use "predictions" field in the task, you must put "data" field in the task too'
)
# annotations
annotations = data.get('annotations') or []
cancelled_annotations = 0
if annotations:
if 'data' not in data:
raise ValueError(
'If you use "annotations" field in the task, you must put "data" field in the task too'
)
cancelled_annotations = len([a for a in annotations if a.get('was_cancelled', False)])
storage_task_data_validator = load_func(getattr(settings, 'STORAGE_TASK_DATA_VALIDATOR', None))
if storage_task_data_validator:
storage_task_data_validator(project, data)
if 'data' in data and isinstance(data['data'], dict):View on GitHub (pinned to 0b49e9b539)
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.
Example fix
// before
task = {'predictions': [{'result': [...], 'score': 0.9}]}
storage.add_task(task)
// after
task = {'data': {'image': 's3://bucket/img.jpg'}, 'predictions': [{'result': [...], 'score': 0.9}]}
storage.add_task(task) Defensive patterns
Strategy: validation
Validate before calling
def validate_task_payload(task: dict):
if isinstance(task, dict) and (task.get('predictions') or task.get('annotations')) and 'data' not in task:
raise ValueError('Task payload with predictions/annotations must also include "data"') Type guard
def is_valid_task_payload(task: dict) -> bool:
return not (isinstance(task, dict) and (task.get('predictions') or task.get('annotations')) and 'data' not in task) Try / catch
try:
storage.add_task(task)
except ValueError as e:
if '"data" field in the task' in str(e):
logger.error('Malformed task payload (missing data): %s', task)
else:
raise Prevention
- 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.
When it happens
Trigger: Calling add_task (directly or via storage sync _scan_and_create_links / create_tasks) with a dict like {'predictions': [...]} that omits 'data'.
Common situations: Importing JSON files exported from another project where data was stripped; hand-written imports that include only predictions; script-generated tasks with incomplete payloads.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- Prediction validation failed ({len(validation_errors)} error
- If you use "annotations" field in the task, you must put "da
- {'predictions': prediction_errors}
- "url" must be 2048 characters or fewer
- {item} contains invalid "task" field: task ID {task_id} not
AI-assisted analysis of HumanSignal/label-studio@0b49e9b539 (2026-08-29).
Data as JSON: /api/errors/6e8c12bf800f3894.
Report an issue: GitHub.