Describe the bug
When a metadata filter uses an operator that isn't supported (a typo such as gt/lt/eq/contains instead of >/</==/in, or a wrong logical operator like XOR), document_matches_filter raises a bare KeyError with no guidance, instead of the FilterError that the rest of the filter validation already uses.
This happens in haystack/utils/filters.py, which is the shared filter engine used by InMemoryDocumentStore and every external document store (Weaviate, Pinecone, OpenSearch, …), so the cryptic error surfaces across all stores.
Error message
To Reproduce
from haystack.dataclasses import Document
from haystack.utils.filters import document_matches_filter
doc = Document(content="x", meta={"year": 2020})
# comparison operator typo
document_matches_filter({"field": "meta.year", "operator": "gt", "value": 2000}, doc)
# -> KeyError: 'gt'
# logical operator typo
document_matches_filter(
{"operator": "XOR", "conditions": [{"field": "meta.year", "operator": "==", "value": 2020}]},
doc,
)
# -> KeyError: 'XOR'
Expected behavior
A FilterError explaining that the operator is unsupported and listing the valid operators — consistent with how other malformed filters (missing keys, wrong value types) are already reported.
System:
Describe the bug
When a metadata filter uses an operator that isn't supported (a typo such as
gt/lt/eq/containsinstead of>/</==/in, or a wrong logical operator likeXOR),document_matches_filterraises a bareKeyErrorwith no guidance, instead of theFilterErrorthat the rest of the filter validation already uses.This happens in
haystack/utils/filters.py, which is the shared filter engine used byInMemoryDocumentStoreand every external document store (Weaviate, Pinecone, OpenSearch, …), so the cryptic error surfaces across all stores.Error message
To Reproduce
Expected behavior
A
FilterErrorexplaining that the operator is unsupported and listing the valid operators — consistent with how other malformed filters (missing keys, wrong value types) are already reported.System: