{"record":{"id":"119d3bc00cd874b0","repo":"deepset-ai/haystack","slug":"value-key-missing-in-condition","errorCode":null,"errorMessage":"'value' key missing in {condition}","messagePattern":"'value' key missing in (.+?)","errorType":"exception","errorClass":"FilterError","httpStatus":null,"severity":"error","filePath":"haystack/utils/filters.py","lineNumber":302,"sourceCode":"\n\ndef _comparison_condition(\n    condition: dict[str, Any], document: Document | ByteStream, strict_datetime_comparison: bool\n) -> bool:\n    if \"field\" not in condition:\n        # 'field' key is only found in comparison dictionaries.\n        # We assume this is a logic dictionary since it's not present.\n        return _logic_condition(\n            condition=condition, document=document, strict_datetime_comparison=strict_datetime_comparison\n        )\n    field: str = condition[\"field\"]\n\n    if \"operator\" not in condition:\n        msg = f\"'operator' key missing in {condition}\"\n        raise FilterError(msg)\n    if \"value\" not in condition:\n        msg = f\"'value' key missing in {condition}\"\n        raise FilterError(msg)\n\n    if \".\" in field:\n        # Handles fields formatted like so:\n        # 'meta.person.name'\n        parts = field.split(\".\")\n        document_value = getattr(document, parts[0])\n        for part in parts[1:]:\n            if not isinstance(document_value, dict) or part not in document_value:\n                # If a field is not found (or an intermediate value is not a dict,\n                # e.g. None) we treat it as None\n                document_value = None\n                break\n            document_value = document_value[part]\n    elif field not in [f.name for f in fields(document)]:\n        # Converted legacy filters don't add the `meta.` prefix, so we assume\n        # that all filter fields that are not actual fields in Document are converted\n        # filters.\n        #","sourceCodeStart":284,"sourceCodeEnd":320,"githubUrl":"https://github.com/deepset-ai/haystack/blob/e318778c9bf60a1963e3b5f451359655dd696c30/haystack/utils/filters.py#L284-L320","documentation":"FilterError raised by `_comparison_condition` in haystack/utils/filters.py when a comparison condition dict lacks the required 'value' key. Haystack filters use the structured form {'field': ..., 'operator': ..., 'value': ...}, and the value is what the document attribute is compared against; without it the comparison is undefined.","triggerScenarios":"Calling document_matches_filter/_and/_or (directly or via run(... filters=...) on DocumentFilter-like components) with a condition dict that has 'field' and 'operator' but no 'value', e.g. {'field': 'meta.year', 'operator': '=='} instead of {'field': 'meta.year', 'operator': '==', 'value': 2024}.","commonSituations":"Hand-written filter dicts with a missing key; programmatically built filters where a variable holding the value is None and the key was conditionally omitted; older 1.x-style filter dicts migrated to 2.x without all keys.","solutions":["Add the 'value' key to the condition dict: {'field': ..., 'operator': ..., 'value': ...}","Check that any code building filter dicts programmatically always includes 'value', even for empty-string or None values","Validate the filter dict structure before passing it to the component"],"exampleFix":"// before\nfilters = {\"field\": \"meta.year\", \"operator\": \"==\"}\n// after\nfilters = {\"field\": \"meta.year\", \"operator\": \"==\", \"value\": 2024}","handlingStrategy":"validation","validationCode":"REQUIRED = {\"field\", \"operator\", \"value\"}\ndef validate_filter(cond):\n    missing = REQUIRED - cond.keys()\n    if missing:\n        raise ValueError(f\"filter condition missing keys: {missing}\")","typeGuard":"def is_valid_condition(c) -> bool:\n    return isinstance(c, dict) and {\"field\", \"operator\", \"value\"}.issubset(c.keys())","tryCatchPattern":"from haystack.utils import FilterError\ntry:\n    doc_matches = document_matches_filter(document, condition)\nexcept FilterError as e:\n    log.error(\"Invalid filter condition: %s\", e)\n    doc_matches = False","preventionTips":["Always build filters with all three keys: field, operator, value","Centralize filter construction in one factory function that validates keys","Never conditionally omit the value key; include None explicitly if needed"],"tags":["haystack","filters","filtererror","missing-key"],"backgroundTag":"missing-required-key","analyzedSha":"e318778c9bf60a1963e3b5f451359655dd696c30","analyzedAt":"2026-08-30T11:45:20.711Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}