{"record":{"id":"c3542155a1fc1dc1","repo":"HumanSignal/label-studio","slug":"preannotated-fields","errorCode":null,"errorMessage":"preannotated_fields","messagePattern":"preannotated_fields","errorType":"validation","errorClass":"ValidationError","httpStatus":400,"severity":"error","filePath":"label_studio/data_import/functions.py","lineNumber":281,"sourceCode":"                            'from_name': field,\n                            'to_name': to_name,\n                            'type': prediction_type,\n                            'value': prediction_value,\n                        }\n                    ],\n                    'score': 1.0,\n                    'model_version': 'preannotated',\n                }\n\n                predictions.append(prediction)\n\n        # Create new task structure\n        new_task = {'data': task_data, 'predictions': predictions}\n        new_tasks.append(new_task)\n\n    # If there are validation errors, raise them\n    if validation_errors and raise_errors:\n        raise ValidationError({'preannotated_fields': validation_errors})\n\n    return new_tasks\n\n\npost_process_reimport = load_func(settings.POST_PROCESS_REIMPORT)\n\n\ndef _async_reimport_background_streaming(reimport, project, organization_id, user):\n    \"\"\"Streaming version of reimport that processes tasks in batches to reduce memory usage\"\"\"\n    try:\n        # Get batch size from settings or use default\n        batch_size = settings.REIMPORT_BATCH_SIZE\n\n        # Initialize counters\n        total_task_count = 0\n        total_annotation_count = 0\n        total_prediction_count = 0\n        all_found_formats = {}","sourceCodeStart":263,"sourceCodeEnd":299,"githubUrl":"https://github.com/HumanSignal/label-studio/blob/0b49e9b53917880baf1dd85d574fe5541a9aafb2/label_studio/data_import/functions.py#L263-L299","documentation":"reformat_predictions converts legacy 'preannotated_fields' style data into task+predictions structures. While processing it collects validation errors about missing pre-annotation fields, and if any were found and raise_errors is set, it raises ValidationError({'preannotated_fields': validation_errors}). The dict key 'preannotated_fields' in the response identifies this error family.","triggerScenarios":"Importing tasks whose data references pre-annotation fields (e.g. data keys configured as pre-annotated sources) that are missing or invalid in the item, during sync_import, async import background processing, or streaming re-import — with raise_errors enabled.","commonSituations":"Legacy pre-annotation workflows where the expected data keys were renamed or omitted; re-importing old exports into projects with different data key configuration; templates expecting {data}['annotations']-style fields that the payload lacks; automated pipelines producing tasks without the pre-annotated field keys.","solutions":["Read validation_errors under the 'preannotated_fields' key; each entry names the missing/invalid field","Add the expected pre-annotated field keys to each task's data object","Update the import payload to the current annotations/predictions format instead of legacy preannotated_fields","Check the project/template configuration for which data keys it expects","Verify upstream data generation emits the required keys for every task"],"exampleFix":"// before: task data missing the pre-annotated field\n{\"data\": {\"text\": \"hello\"}}\n// after: include expected preannotated field\n{\"data\": {\"text\": \"hello\", \"preannotated_choices\": [\"positive\"]}}","handlingStrategy":"validation","validationCode":"required = {'preannotated_choices'}  # keys the template/project expects\nfor t in tasks:\n    missing = required - t.get('data', {}).keys()\n    if missing:\n        raise ValueError(f'task data missing preannotated fields: {missing}')","typeGuard":"def has_preannotated_fields(task: dict, required: set) -> bool:\n    data = task.get('data') if isinstance(task, dict) else None\n    return isinstance(data, dict) and required.issubset(data.keys())","tryCatchPattern":"try:\n    requests.post(import_url, headers=H, json=tasks).raise_for_status()\nexcept requests.HTTPError as e:\n    detail = e.response.json()\n    if 'preannotated_fields' in detail:\n        log.error('Pre-annotation field errors: %s', detail['preannotated_fields'])","preventionTips":["Match task data keys to the template's expected pre-annotated fields before import","Migrate legacy preannotated_fields payloads to the current predictions format","Schema-check generated task dicts (data key presence) in your pipeline"],"tags":["django","rest-framework","pre-annotations","import","validation"],"backgroundTag":"missing-required-field","analyzedSha":"0b49e9b53917880baf1dd85d574fe5541a9aafb2","analyzedAt":"2026-08-29T00:39:52.578Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}