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

FileTypeRouter.__init__ raises this ValueError when the mime_types list is empty, since the router needs at least one MIME type pattern to define its output slots.

Source

Thrown at haystack/components/routers/file_type_router.py:82

    ) -> None:
        """
        Initialize the FileTypeRouter component.

        :param mime_types:
            A list of MIME types or regex patterns to classify the input files or byte streams.
            (for example: `["text/plain", "audio/x-wav", "image/jpeg"]`).

        :param additional_mimetypes:
            A dictionary containing the MIME type to add to the mimetypes package to prevent unsupported or non-native
            packages from being unclassified.
            (for example: `{"application/vnd.openxmlformats-officedocument.wordprocessingml.document": ".docx"}`).

        :param raise_on_failure:
            If True, raises FileNotFoundError when a file path doesn't exist.
            If False (default), only emits a warning when a file path doesn't exist.
        """
        if not mime_types:
            raise ValueError("The list of mime types cannot be empty.")

        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:
                raise ValueError(f"Invalid MIME type or regex pattern '{mime_type}'.") from e
            self.mime_type_patterns.append(pattern)

        # the actual output type is list[Union[Path, ByteStream]],
        # but this would cause PipelineConnectError with Converters
        component.set_output_types(
            self,
            unclassified=list[str | Path | ByteStream],

View on GitHub (pinned to e318778c9b)

Solutions

  1. Provide a non-empty list of MIME types, e.g. ['image/png', 'application/pdf']
  2. Check upstream logic that builds the list before constructing the router

Example fix

# before
router = FileTypeRouter(mime_types=[])
# after
router = FileTypeRouter(mime_types=["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 FileTypeRouter")

Type guard

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

Try / catch

try:
    router = FileTypeRouter(mime_types=mime_types)
except ValueError as e:
    if "cannot be empty" in str(e):
        router = FileTypeRouter(mime_types=["application/pdf"])
    else:
        raise

Prevention

When it happens

Trigger: FileTypeRouter(mime_types=[]) or a falsy mime_types argument (None, empty list).

Common situations: Empty configuration file; building the list dynamically from user input that was empty.

Related errors


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