{"record":{"id":"dddbc14841d6288c","repo":"microsoft/semantic-kernel","slug":"only-comparisons-are-supported","errorCode":null,"errorMessage":"Only == comparisons are supported.","messagePattern":"Only == comparisons are supported\\.","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/_search_shared.py","lineNumber":33,"sourceCode":"    \"\"\"Visitor to parse a lambda function for Brave and Google Search filters.\"\"\"\n\n    def __init__(self, valid_parameters: list[str]):\n        \"\"\"Initialize the visitor with a list of valid parameters.\"\"\"\n        self.filters: list[dict[str, str]] = []\n        self.valid_parameters = valid_parameters\n\n    @override\n    def visit_Lambda(self, node):\n        self.visit(node.body)\n\n    @override\n    def visit_Compare(self, node):\n        # Only support x.FIELD == VALUE\n        if not (isinstance(node.left, ast.Attribute) and isinstance(node.left.value, ast.Name)):\n            raise NotImplementedError(\"Left side must be x.FIELD.\")\n        field = node.left.attr\n        if not (len(node.ops) == 1 and isinstance(node.ops[0], ast.Eq)):\n            raise NotImplementedError(\"Only == comparisons are supported.\")\n        right = node.comparators[0]\n        if isinstance(right, ast.Constant):\n            if right.value is None:\n                raise NotImplementedError(\"None values are not supported.\")\n            value = str(right.value)\n        else:\n            raise NotImplementedError(\"Only constant values are supported on the right side.\")\n        if field not in self.valid_parameters:\n            raise ValueError(f\"Field '{field}' is not supported.\")\n        self.filters.append({field: quote_plus(value)})\n\n    @override\n    def visit_BoolOp(self, node):\n        if not isinstance(node.op, ast.And):\n            raise NotImplementedError(\"Only 'and' of == comparisons is supported.\")\n        for v in node.values:\n            self.visit(v)\n","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/_search_shared.py#L15-L51","documentation":"The visitor supports only a single equality operator (ast.Eq). A Compare node whose ops are not exactly one `==` raises NotImplementedError. Any other operator (!=, <, >, <=, >=, in, is) or chained comparisons are rejected.","triggerScenarios":"Using an inequality or membership test in the filter lambda: `lambda x: x.field != \"v\"`, `lambda x: x.field in (...)`, `lambda x: x.field > 5`, or a chained comparison `lambda x: 1 == x.field == 1`.","commonSituations":"Assuming range or membership filters are supported; copying OData-style filter syntax into the lambda.","solutions":["Express the filter as a single `==` equality (`lambda x: x.field == \"v\"`).","For multi-value matching, combine several `x.field == v` clauses with `and` (see BoolOp support) rather than `in`."],"exampleFix":"// before\nlambda x: x.category != \"ads\"\nlambda x: x.region in (\"us\", \"eu\")\n\n// after\nlambda x: x.category == \"news\"\n# membership must be expressed via explicit equality (no 'in' support)","handlingStrategy":"validation","validationCode":"import ast\nnode = ast.parse(filter_src, mode='eval').body\ndef check_eq(n):\n    if isinstance(n, ast.Compare):\n        assert len(n.ops) == 1 and isinstance(n.ops[0], ast.Eq), 'only == supported'\n    if isinstance(n, ast.BoolOp):\n        for v in n.values: check_eq(v)\ncheck_eq(node.body)","typeGuard":"def is_single_eq(node: ast.Compare) -> bool:\n    return len(node.ops) == 1 and isinstance(node.ops[0], ast.Eq)","tryCatchPattern":null,"preventionTips":["Use only == in filter lambdas","Express multi-value matches as separate == clauses joined by 'and'","Avoid range/membership operators which are unsupported"],"tags":["search","filters","lambda","ast"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}