{"record":{"id":"e16053a2f0508e1c","repo":"deepset-ai/haystack","slug":"at-least-one-of-mime-type-meta-field-or-file-pa","errorCode":null,"errorMessage":"At least one of 'mime_type_meta_field' or 'file_path_meta_field' must be provided to determine MIME types.","messagePattern":"At least one of 'mime_type_meta_field' or 'file_path_meta_field' must be provided to determine MIME types\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"haystack/components/routers/document_type_router.py","lineNumber":89,"sourceCode":"            (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:\n                raise ValueError(f\"Invalid regex pattern '{mime_type}'.\") from e\n            self._mime_type_patterns.append(pattern)\n","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/deepset-ai/haystack/blob/e318778c9bf60a1963e3b5f451359655dd696c30/haystack/components/routers/document_type_router.py#L71-L107","documentation":"DocumentTypeRouter.__init__ raises this ValueError when neither mime_type_meta_field nor file_path_meta_field is provided, because the router has no way to determine each document's MIME type.","triggerScenarios":"DocumentTypeRouter(mime_types=['text/html']) with both meta field arguments left as None.","commonSituations":"Forgetting that MIME type detection relies on document metadata (custom field or file path); migrating code that dropped one of the two fields.","solutions":["Pass mime_type_meta_field='meta.mimetype' (or your metadata key) and/or file_path_meta_field='meta.file_path'","Ensure documents carry the referenced metadata key at runtime"],"exampleFix":"# before\nrouter = DocumentTypeRouter(mime_types=[\"text/html\"])\n# after\nrouter = DocumentTypeRouter(mime_types=[\"text/html\"], mime_type_meta_field=\"meta.mimetype\")","handlingStrategy":"validation","validationCode":"if mime_type_meta_field is None and file_path_meta_field is None:\n    raise ValueError(\"Provide mime_type_meta_field or file_path_meta_field\")","typeGuard":"def has_meta_field(args: dict) -> bool:\n    return args.get(\"mime_type_meta_field\") is not None or args.get(\"file_path_meta_field\") is not None","tryCatchPattern":"try:\n    router = DocumentTypeRouter(mime_types=[\"text/html\"])\nexcept ValueError as e:\n    if \"must be provided\" in str(e):\n        router = DocumentTypeRouter(mime_types=[\"text/html\"], mime_type_meta_field=\"meta.mimetype\")\n    else:\n        raise","preventionTips":["Always supply mime_type_meta_field or file_path_meta_field at construction","Ensure documents actually carry the chosen metadata key at runtime","Centralize router construction in a factory that sets the meta fields"],"tags":["python","validation","router","mime-type"],"backgroundTag":"missing-required-parameter","analyzedSha":"e318778c9bf60a1963e3b5f451359655dd696c30","analyzedAt":"2026-08-30T11:45:20.711Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}