{"record":{"id":"d5a52845e95c2aa3","repo":"HumanSignal/label-studio","slug":"failed-to-parse-input-file-self-file-name-extr","errorCode":null,"errorMessage":"Failed to parse input file {self.file_name}: {extract_message(exc)}","messagePattern":"Failed to parse input file (.+?): (.+?)","errorType":"validation","errorClass":"ValidationError","httpStatus":400,"severity":"error","filePath":"label_studio/data_import/models.py","lineNumber":279,"sourceCode":"                tasks = self.read_tasks_list_from_txt()\n            elif file_format == '.json':\n                tasks = self.read_tasks_list_from_json()\n\n            # otherwise - only one object tag should be presented in label config\n            elif not self.project.one_object_in_label_config:\n                raise ValidationError(\n                    'Your label config has more than one data key and direct file upload supports only '\n                    'one data key. To import data with multiple data keys, use a JSON or CSV file.'\n                )\n\n            # file as a single asset\n            elif file_format in ('.html', '.htm', '.xml'):\n                tasks = self.read_task_from_hypertext_body()\n            else:\n                tasks = self.read_task_from_uploaded_file()\n\n        except Exception as exc:\n            raise ValidationError('Failed to parse input file ' + self.file_name + ': ' + extract_message(exc))\n        return tasks\n\n    def read_tasks_streaming(self, file_as_tasks_list=True, batch_size=100):\n        \"\"\"Streaming version of read_tasks that yields tasks in batches for memory efficiency\"\"\"\n        file_format = self.format\n\n        try:\n            # For JSON files, use streaming JSON parser\n            if file_format == '.json':\n                for batch in self.read_tasks_list_from_json_streaming(batch_size):\n                    yield batch\n\n            # For other file types, use existing methods but yield in batches\n            else:\n                # Use existing non-streaming methods for non-JSON files\n                if file_format == '.csv' and file_as_tasks_list:\n                    tasks = self.read_tasks_list_from_csv()\n                elif file_format == '.tsv' and file_as_tasks_list:","sourceCodeStart":261,"sourceCodeEnd":297,"githubUrl":"https://github.com/HumanSignal/label-studio/blob/0b49e9b53917880baf1dd85d574fe5541a9aafb2/label_studio/data_import/models.py#L261-L297","documentation":"read_tasks wraps any exception from its format-specific readers (json/csv/tsv/txt/hypertext/generic upload) into ValidationError('Failed to parse input file <name>: <inner>'). It is a catch-all, so the actionable cause is the message appended by extract_message(exc).","triggerScenarios":"Any parse failure inside read_tasks for the uploaded file's format: malformed JSON, bad CSV structure, encoding errors, or the multiple-data-key ValidationError raised at models.py:267.","commonSituations":"Wrong file extension (CSV named .txt); invalid encoding; empty file; label config mismatch raising the nested multiple-data-key error; corrupted download from storage.","solutions":["Inspect the inner message after 'Failed to parse input file ...:' and fix the root cause","Verify the file extension matches the actual content and the content parses (json.tool, csv linter)","Re-save the file as UTF-8; if the config error is the cause, use JSON/CSV or fix the label config"],"exampleFix":"// before: content is CSV but extension is .txt causing wrong parser\n# rename data.csv.txt -> data.csv\n// after: correct format/extension pairing\ncp data.csv.txt data.csv && import data.csv","handlingStrategy":"try-catch","validationCode":"# pre-parse with the matching reader\nimport json, csv\ntext = open(path, encoding='utf8').read()\nif path.endswith('.json'):\n    json.loads(text)\nelif path.endswith('.csv'):\n    list(csv.reader(text.splitlines()))","typeGuard":null,"tryCatchPattern":"try:\n    tasks = fu.read_tasks()\nexcept ValidationError as e:\n    inner = str(e).split(': ', 1)[-1]  # real cause after file name\n    logger.error(\"Import failed, root cause: %s\", inner)","preventionTips":["Match file extension to actual content","Pre-parse files locally before upload","Fix nested causes (JSON syntax, data-key mismatch) surfaced in the message"],"tags":["parsing","data-import","file-upload"],"backgroundTag":"file-parse-error","analyzedSha":"0b49e9b53917880baf1dd85d574fe5541a9aafb2","analyzedAt":"2026-08-29T00:39:52.578Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}