deepset-ai/haystack · error · FilterError
'conditions' key missing in {condition}
Error message
'conditions' key missing in {condition} What it means
A logical filter condition must include a 'conditions' key holding the list of sub-conditions. If 'operator' exists but 'conditions' is missing, _logic_condition raises this FilterError.
Source
Thrown at haystack/utils/filters.py:275
"!=": _not_equal,
">": _greater_than,
">=": _greater_than_equal,
"<": _less_than,
"<=": _less_than_equal,
"in": _in,
"not in": _not_in,
}
def _logic_condition(
condition: dict[str, Any], document: Document | ByteStream, strict_datetime_comparison: bool
) -> bool:
if "operator" not in condition:
msg = f"'operator' key missing in {condition}"
raise FilterError(msg)
if "conditions" not in condition:
msg = f"'conditions' key missing in {condition}"
raise FilterError(msg)
operator: str = condition["operator"]
if operator not in LOGICAL_OPERATORS:
msg = f"Unknown logical operator '{operator}'. Valid operators are: {sorted(LOGICAL_OPERATORS)}"
raise FilterError(msg)
conditions: list[dict[str, Any]] = condition["conditions"]
return LOGICAL_OPERATORS[operator](
document=document, conditions=conditions, strict_datetime_comparison=strict_datetime_comparison
)
def _comparison_condition(
condition: dict[str, Any], document: Document | ByteStream, strict_datetime_comparison: bool
) -> bool:
if "field" not in condition:
# 'field' key is only found in comparison dictionaries.
# We assume this is a logic dictionary since it's not present.
return _logic_condition(
condition=condition, document=document, strict_datetime_comparison=strict_datetime_comparisonView on GitHub (pinned to e318778c9b)
Solutions
- Add a "conditions" key containing a list of condition dicts.
- Fix key typos (must be exactly 'conditions').
- Build filters via the documented schema and validate nested lists before applying.
Example fix
// before
filters = {"operator": "AND", "condition": [{"field": "meta.x", "operator": "==", "value": 1}]}
// after
filters = {"operator": "AND", "conditions": [{"field": "meta.x", "operator": "==", "value": 1}]} Defensive patterns
Strategy: validation
Validate before calling
assert "conditions" in condition, f"logical condition needs 'conditions' list: {condition}" Type guard
def has_conditions(c: dict) -> bool:
return isinstance(c.get("conditions"), list) and len(c["conditions"]) > 0 Try / catch
try:
ok = document_matches_filter(doc, filters)
except FilterError as e:
raise ValueError(f"malformed filter: {e}") from e Prevention
- Spell the key exactly 'conditions' (plural).
- Ensure each logical operator is paired with a non-empty conditions list.
- Validate nested filter structures recursively.
When it happens
Trigger: Passing {"operator": "AND"} with no 'conditions' list, or a condition whose sub-conditions were stored under another key name.
Common situations: Typos like 'condition' or 'filters' instead of 'conditions'; partially constructed filters; deserialized configs with a wrong schema version.
Related errors
- 'operator' key missing in {condition}
- Filter value can't be of type {type(filter_value)} using ope
- Can't compare strings using operators '>', '>=', '<', '<='.
- Filter value must be a `list` when using operator 'in' or 'n
- Unknown logical operator '{operator}'. Valid operators are:
AI-assisted analysis of deepset-ai/haystack@e318778c9b (2026-08-30).
Data as JSON: /api/errors/dc345d4e552cf613.
Report an issue: GitHub.