{"record":{"id":"9fc83e756369bbf8","repo":"HumanSignal/label-studio","slug":"prediction-must-have-result-fields","errorCode":null,"errorMessage":"Prediction must have \"result\" fields","messagePattern":"Prediction must have \"result\" fields","errorType":"validation","errorClass":"ValidationError","httpStatus":400,"severity":"error","filePath":"label_studio/tasks/validation.py","lineNumber":191,"sourceCode":"\n                ok = 'result' in annotation\n                if not ok:\n                    raise ValidationError('Annotation must have \"result\" fields')\n\n                # check result is list\n                if not isinstance(annotation.get('result', []), list):\n                    raise ValidationError('\"result\" field in annotation must be list')\n\n            # task[predictions]\n            self.raise_if_wrong_class(task, 'predictions', list)\n            for prediction in task.get('predictions', []):\n                if not isinstance(prediction, dict):\n                    logger.warning('Prediction must be dict, but \"%s\" found', str(type(prediction)))\n                    continue\n\n                ok = 'result' in prediction\n                if not ok:\n                    raise ValidationError('Prediction must have \"result\" fields')\n\n            # task[meta]\n            self.raise_if_wrong_class(task, 'meta', (dict, list))\n\n        # task is data as is, validate task as data and move it to task['data']\n        else:\n            self.check_data_and_root(self.project, task, dict_is_root=True)\n            task = {'data': task}\n\n        return task\n\n    @staticmethod\n    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)","sourceCodeStart":173,"sourceCodeEnd":209,"githubUrl":"https://github.com/HumanSignal/label-studio/blob/0b49e9b53917880baf1dd85d574fe5541a9aafb2/label_studio/tasks/validation.py#L173-L209","documentation":"TaskValidator.validate raises this when a task item's 'predictions' list contains a dict entry without a 'result' key. Predictions follow the same schema as annotations and must include a 'result' array describing the model's proposed labels.","triggerScenarios":"POSTing tasks to the import endpoint with {'predictions': [{'score': 0.9}]} or {'predictions': [{'model_version': 'v1'}]} — prediction dict lacking 'result'. Non-dict prediction entries are skipped with a warning, not this error.","commonSituations":"ML backend output adapters that attach scores/model metadata but omit results; scripts importing pre-annotations that pass an empty prediction shell {} to mark model version; template files where results were stripped.","solutions":["Add 'result' to every prediction dict, e.g. 'result': [] if there are no results","Remove the empty prediction shell entirely if it carries no information","Populate 'result' with the model's output in Label Studio result format ({from_name, to_name, type, value})","Pre-validate: for each p in task.get('predictions', []): assert isinstance(p, dict) and 'result' in p"],"exampleFix":"// before\n{\"data\": {\"text\": \"hi\"}, \"predictions\": [{\"score\": 0.9, \"model_version\": \"v1\"}]}\n// after\n{\"data\": {\"text\": \"hi\"}, \"predictions\": [{\"score\": 0.9, \"model_version\": \"v1\", \"result\": []}]}","handlingStrategy":"validation","validationCode":"def validate_predictions(task):\n    for p in task.get('predictions', []):\n        if isinstance(p, dict) and 'result' not in p:\n            raise ValueError('prediction missing result: %r' % p)","typeGuard":"def has_valid_prediction(p):\n    return isinstance(p, dict) and isinstance(p.get('result'), list)","tryCatchPattern":"try:\n    client.import_tasks(id=project_id, tasks=tasks)\nexcept LabelStudioError as e:\n    if 'Prediction must have \"result\" fields' in str(e):\n        for t in tasks:\n            for p in t.get('predictions', []):\n                if isinstance(p, dict):\n                    p.setdefault('result', [])\n        client.import_tasks(id=project_id, tasks=tasks)\n    else:\n        raise","preventionTips":["Always set 'result' (even []) on prediction dicts","Don't import bare prediction shells {} just to record a model version","Follow the result object shape: from_name, to_name, type, value","Pre-validate predictions with the same code path you use for annotations"],"tags":["validation","task-import","predictions","rest-api"],"backgroundTag":"missing-required-field","analyzedSha":"0b49e9b53917880baf1dd85d574fe5541a9aafb2","analyzedAt":"2026-08-29T00:39:52.578Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}