{"record":{"id":"5b004a460fbd1d7f","repo":"HumanSignal/label-studio","slug":"predictions-prediction-errors","errorCode":null,"errorMessage":"{'predictions': prediction_errors}","messagePattern":"\\{'predictions': prediction_errors\\}","errorType":"validation","errorClass":"ValidationError","httpStatus":400,"severity":"error","filePath":"label_studio/tasks/serializers.py","lineNumber":724,"sourceCode":"                    task_drafts.append(drafts)\n\n                    # extract reviews from snapshot annotations\n                    for annotation in annotations:\n                        reviews = annotation.get('reviews', [])\n                        self._insert_valid_user_reviews(reviews, members_email_to_id, default_user)\n                        task_reviews.append(reviews)\n\n            db_tasks = self.add_tasks(task_annotations, task_predictions, validated_tasks)\n            db_annotations = self.add_annotations(task_annotations, user)\n            prediction_errors = self.add_predictions(task_predictions)\n\n            raise_prediction_errors = True\n            if not flag_set('fflag_feat_utc_210_prediction_validation_15082025', user=ff_user):\n                raise_prediction_errors = False\n\n            # If there are prediction validation errors, raise them\n            if prediction_errors and raise_prediction_errors:\n                raise ValidationError({'predictions': prediction_errors})\n\n            if db_annotations:\n                # Keep ProjectSummary counters in sync for imported annotations so\n                # label-distribution statistics don't require a manual summary reset.\n                self.project.summary.update_created_annotations_and_labels(db_annotations)\n\n        self.post_process_annotations(user, db_annotations, 'imported')\n        self.post_process_tasks(self.project.id, [t.id for t in self.db_tasks])\n        self.post_process_custom_callback(self.project.id, user)\n\n        if flag_set('fflag_feat_back_lsdv_5307_import_reviews_drafts_29062023_short', user=ff_user):\n            with transaction.atomic():\n                # build mapping between new and old ids in annotations,\n                # we need it because annotation ids will be known only after saving to db\n                annotation_mapping = {v.import_id: v.id for v in db_annotations}\n                annotation_mapping[None] = None\n                # the sequence of add_ functions is very important because of references to ids\n                db_drafts = self.add_drafts(task_drafts, db_tasks, annotation_mapping, self.project)","sourceCodeStart":706,"sourceCodeEnd":742,"githubUrl":"https://github.com/HumanSignal/label-studio/blob/0b49e9b53917880baf1dd85d574fe5541a9aafb2/label_studio/tasks/serializers.py#L706-L742","documentation":"Raised in BaseTaskSerializerBulk.create when add_predictions returns validation errors for one or more imported predictions and the feature flag fflag_feat_utc_210_prediction_validation_15082025 is enabled for the org. The errors are wrapped as {'predictions': [...]}, failing the import transaction after tasks may have been staged, so prediction results (bad label values, wrong result types, malformed model output) must be fixed before the batch is accepted.","triggerScenarios":"Importing tasks whose 'predictions' arrays contain results that fail PredictionSerializer validation — e.g. label values not present in the project's labeling config, result entries missing 'from_name'/'to_name'/'type', or invalid score/value shapes — while the UTC-210 prediction-validation flag is on.","commonSituations":"Model-generated pre-annotations using label names that don't match the current label config; exports from projects with a different labeling config; predictions copied from a config that was later renamed/edited.","solutions":["Inspect the 'predictions' detail in the error to find the failing prediction results and fix the label values / result structure","Regenerate predictions with model output that exactly matches the project's current labeling config (label names, from_name/to_name, result type)","Update the project labeling config to include the labels used by the predictions before importing","Strip the 'predictions' key from the import payload if predictions are not needed","Disable the fflag_feat_utc_210_prediction_validation_15082025 flag for the org to restore the old lenient behavior (predictions errors logged, not raised)"],"exampleFix":"// before\n{\"predictions\": [{\"result\": [{\"from_name\": \"sentiment\", \"type\": \"choices\", \"value\": {\"choices\": [\"positive\"]}}]}]}\n// after — 'mood' config label actually defined in the project\n{\"predictions\": [{\"result\": [{\"from_name\": \"mood\", \"to_name\": \"text\", \"type\": \"choices\", \"value\": {\"choices\": [\"positive\"]}}]}]}","handlingStrategy":"try-catch","validationCode":"def check_predictions(tasks, config_labels, config_from_names):\n    for t in tasks:\n        for p in t.get('predictions', []):\n            for r in p.get('result', []):\n                if r.get('from_name') not in config_from_names:\n                    raise ValueError(f\"Unknown from_name {r.get('from_name')!r}\")\n                for lbl in r.get('value', {}).get('choices', []):\n                    if lbl not in config_labels:\n                        raise ValueError(f'Unknown label {lbl!r} not in labeling config')","typeGuard":null,"tryCatchPattern":"from rest_framework.exceptions import ValidationError\ntry:\n    client.import_tasks(project_id, tasks)\nexcept ValidationError as e:\n    if isinstance(e.detail, dict) and 'predictions' in e.detail:\n        bad = e.detail['predictions']\n        # drop or fix invalid predictions, then retry the import\n        for i, err in enumerate(bad):\n            print('Prediction error:', i, err)\n    else:\n        raise","preventionTips":["Generate predictions with label names matching the project's current labeling config","Fetch the labeling config and diff its labels against prediction values before import","Validate a sample prediction batch against PredictionSerializer before bulk import","Keep model output schema (from_name/to_name/type/value) aligned with the config's control tags"],"tags":["django","predictions","import","validation","label-config"],"backgroundTag":"prediction-validation-failed","analyzedSha":"0b49e9b53917880baf1dd85d574fe5541a9aafb2","analyzedAt":"2026-08-29T00:39:52.578Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}