deepset-ai/haystack · error · ValueError

The list of mime types cannot be empty.

Error message

The list of mime types cannot be empty.

What it means

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.

Source

Thrown at haystack/components/routers/document_type_router.py:86

        :param mime_types:
            A list of MIME types or regex patterns to classify the input documents.
            (for example: `["text/plain", "audio/x-wav", "image/jpeg"]`).
        :param mime_type_meta_field:
            Optional name of the metadata field that holds the MIME type.
        :param file_path_meta_field:
            Optional name of the metadata field that holds the file path. Used to infer the MIME type if
            `mime_type_meta_field` is not provided or missing in a document.
        :param additional_mimetypes:
            Optional dictionary mapping MIME types to file extensions to enhance or override the standard
            `mimetypes` module. Useful when working with uncommon or custom file types.
            For example: `{"application/vnd.custom-type": ".custom"}`.

        :raises ValueError: If `mime_types` is empty or if both `mime_type_meta_field` and `file_path_meta_field` are
            not provided.
        """
        if not mime_types:
            raise ValueError("The list of mime types cannot be empty.")

        if mime_type_meta_field is None and file_path_meta_field is None:
            raise ValueError(
                "At least one of 'mime_type_meta_field' or 'file_path_meta_field' must be provided to determine MIME "
                "types."
            )
        self.mime_type_meta_field = mime_type_meta_field
        self.file_path_meta_field = file_path_meta_field

        if additional_mimetypes:
            for mime, ext in additional_mimetypes.items():
                mimetypes.add_type(mime, ext)

        self._mime_type_patterns = []
        for mime_type in mime_types:
            try:
                pattern = re.compile(mime_type)
            except re.error as e:

View on GitHub (pinned to e318778c9b)

Solutions

  1. Pass a non-empty list of MIME type strings, e.g. ['text/html', 'application/pdf']
  2. Verify the source of your mime_types list is populated before constructing the router

Example fix

# before
router = DocumentTypeRouter(mime_types=[])
# after
router = DocumentTypeRouter(mime_types=["text/html", "application/pdf"])
Defensive patterns

Strategy: validation

Validate before calling

if not mime_types:
    raise ValueError("mime_types must be a non-empty list before constructing DocumentTypeRouter")

Type guard

def has_mime_types(mime_types) -> bool:
    return isinstance(mime_types, list) and len(mime_types) > 0

Try / catch

try:
    router = DocumentTypeRouter(mime_types=mime_types, mime_type_meta_field="meta.mimetype")
except ValueError as e:
    if "cannot be empty" in str(e):
        router = DocumentTypeRouter(mime_types=["text/html"], mime_type_meta_field="meta.mimetype")
    else:
        raise

Prevention

When it happens

Trigger: DocumentTypeRouter(mime_types=[]) or DocumentTypeRouter(mime_types=None) or any falsy mime_types argument.

Common situations: Empty config file/list; mime_types built from a filter that matched nothing; default parameter left unset.

Related errors


AI-assisted analysis of deepset-ai/haystack@e318778c9b (2026-08-30). Data as JSON: /api/errors/004330467d041844. Report an issue: GitHub.