{"record":{"id":"004330467d041844","repo":"deepset-ai/haystack","slug":"the-list-of-mime-types-cannot-be-empty","errorCode":null,"errorMessage":"The list of mime types cannot be empty.","messagePattern":"The list of mime types cannot be empty\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"haystack/components/routers/document_type_router.py","lineNumber":86,"sourceCode":"\n        :param mime_types:\n            A list of MIME types or regex patterns to classify the input documents.\n            (for example: `[\"text/plain\", \"audio/x-wav\", \"image/jpeg\"]`).\n        :param mime_type_meta_field:\n            Optional name of the metadata field that holds the MIME type.\n        :param file_path_meta_field:\n            Optional name of the metadata field that holds the file path. Used to infer the MIME type if\n            `mime_type_meta_field` is not provided or missing in a document.\n        :param additional_mimetypes:\n            Optional dictionary mapping MIME types to file extensions to enhance or override the standard\n            `mimetypes` module. Useful when working with uncommon or custom file types.\n            For example: `{\"application/vnd.custom-type\": \".custom\"}`.\n\n        :raises ValueError: If `mime_types` is empty or if both `mime_type_meta_field` and `file_path_meta_field` are\n            not provided.\n        \"\"\"\n        if not mime_types:\n            raise ValueError(\"The list of mime types cannot be empty.\")\n\n        if mime_type_meta_field is None and file_path_meta_field is None:\n            raise ValueError(\n                \"At least one of 'mime_type_meta_field' or 'file_path_meta_field' must be provided to determine MIME \"\n                \"types.\"\n            )\n        self.mime_type_meta_field = mime_type_meta_field\n        self.file_path_meta_field = file_path_meta_field\n\n        if additional_mimetypes:\n            for mime, ext in additional_mimetypes.items():\n                mimetypes.add_type(mime, ext)\n\n        self._mime_type_patterns = []\n        for mime_type in mime_types:\n            try:\n                pattern = re.compile(mime_type)\n            except re.error as e:","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/deepset-ai/haystack/blob/e318778c9bf60a1963e3b5f451359655dd696c30/haystack/components/routers/document_type_router.py#L68-L104","documentation":"DocumentTypeRouter.__init__ raises this ValueError when constructed with an empty mime_types list. The router needs at least one MIME type to create output slots.","triggerScenarios":"DocumentTypeRouter(mime_types=[]) or DocumentTypeRouter(mime_types=None) or any falsy mime_types argument.","commonSituations":"Empty config file/list; mime_types built from a filter that matched nothing; default parameter left unset.","solutions":["Pass a non-empty list of MIME type strings, e.g. ['text/html', 'application/pdf']","Verify the source of your mime_types list is populated before constructing the router"],"exampleFix":"# before\nrouter = DocumentTypeRouter(mime_types=[])\n# after\nrouter = DocumentTypeRouter(mime_types=[\"text/html\", \"application/pdf\"])","handlingStrategy":"validation","validationCode":"if not mime_types:\n    raise ValueError(\"mime_types must be a non-empty list before constructing DocumentTypeRouter\")","typeGuard":"def has_mime_types(mime_types) -> bool:\n    return isinstance(mime_types, list) and len(mime_types) > 0","tryCatchPattern":"try:\n    router = DocumentTypeRouter(mime_types=mime_types, mime_type_meta_field=\"meta.mimetype\")\nexcept ValueError as e:\n    if \"cannot be empty\" in str(e):\n        router = DocumentTypeRouter(mime_types=[\"text/html\"], mime_type_meta_field=\"meta.mimetype\")\n    else:\n        raise","preventionTips":["Never pass a literal empty list; ensure defaults provide at least one MIME type","Check the list source (config/filter) yields entries before construction"],"tags":["python","validation","router","mime-type"],"backgroundTag":"empty-required-list","analyzedSha":"e318778c9bf60a1963e3b5f451359655dd696c30","analyzedAt":"2026-08-30T11:45:20.711Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}