deepset-ai/haystack · error · ValueError
At least one of 'mime_type_meta_field' or 'file_path_meta_fi
Error message
At least one of 'mime_type_meta_field' or 'file_path_meta_field' must be provided to determine MIME types.
What it means
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.
Source
Thrown at haystack/components/routers/document_type_router.py:89
(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:
raise ValueError(f"Invalid regex pattern '{mime_type}'.") from e
self._mime_type_patterns.append(pattern)
View on GitHub (pinned to e318778c9b)
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
Example fix
# before router = DocumentTypeRouter(mime_types=["text/html"]) # after router = DocumentTypeRouter(mime_types=["text/html"], mime_type_meta_field="meta.mimetype")
Defensive patterns
Strategy: validation
Validate before calling
if mime_type_meta_field is None and file_path_meta_field is None:
raise ValueError("Provide mime_type_meta_field or file_path_meta_field") Type guard
def has_meta_field(args: dict) -> bool:
return args.get("mime_type_meta_field") is not None or args.get("file_path_meta_field") is not None Try / catch
try:
router = DocumentTypeRouter(mime_types=["text/html"])
except ValueError as e:
if "must be provided" in str(e):
router = DocumentTypeRouter(mime_types=["text/html"], mime_type_meta_field="meta.mimetype")
else:
raise Prevention
- 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
When it happens
Trigger: DocumentTypeRouter(mime_types=['text/html']) with both meta field arguments left as None.
Common situations: Forgetting that MIME type detection relies on document metadata (custom field or file path); migrating code that dropped one of the two fields.
Understand the failure class
Background: Missing required parameter errors: what 'X is required' and 'the required X param is missing' mean, and how to fix them — this error's family across 27 libraries.
Related errors
- The list of mime types cannot be empty.
- The list of mime types cannot be empty.
- Invalid template for condition: {condition_value}
- Invalid template for output: {output!r} (type: {type(output)
- Invalid template for output: {output}
AI-assisted analysis of deepset-ai/haystack@e318778c9b (2026-08-30).
Data as JSON: /api/errors/e16053a2f0508e1c.
Report an issue: GitHub.