{"record":{"id":"5b477fbc50967f6b","repo":"microsoft/semantic-kernel","slug":"only-constant-values-are-supported-on-the-right-si","errorCode":null,"errorMessage":"Only constant values are supported on the right side.","messagePattern":"Only constant values are supported on the right side\\.","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/_search_shared.py","lineNumber":40,"sourceCode":"    @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":22,"sourceCodeEnd":51,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/_search_shared.py#L22-L51","documentation":"The right-hand side of the equality must be an ast.Constant. Anything else (a variable name, an attribute, a call, a BinOp) raises NotImplementedError, because the visitor needs a literal to stringify and URL-encode.","triggerScenarios":"Using a non-literal on the right side: `lambda x: x.field == some_var`, `lambda x: x.field == other.attr`, `lambda x: x.field == func()`, or `lambda x: x.field == 1 + 1`.","commonSituations":"Referencing an outer variable or calling a helper in the lambda; assuming the closure is evaluated.","solutions":["Inline a literal constant on the right side (`lambda x: x.field == \"news\"`).","Close over the value by building the lambda after binding it to a constant, but ensure the AST node is still an ast.Constant (a f-string-built lambda will not work; pass the literal directly)."],"exampleFix":"// before\ntarget = \"news\"\nlambda x: x.category == target  # 'target' is a Name, not a Constant\n\n// after\ntarget = \"news\"\nlambda x: x.category == \"news\"  # literal inlined; or pre-format the lambda text","handlingStrategy":"validation","validationCode":"import ast\nnode = ast.parse(filter_src, mode='eval').body\ndef check_const(n):\n    if isinstance(n, ast.Compare):\n        assert isinstance(n.comparators[0], ast.Constant), 'right side must be a constant'\n    if isinstance(n, ast.BoolOp):\n        for v in n.values: check_const(v)\ncheck_const(node.body)","typeGuard":"def rhs_is_constant(node: ast.Compare) -> bool:\n    return isinstance(node.comparators[0], ast.Constant)","tryCatchPattern":null,"preventionTips":["Inline literal values on the right side of filter comparisons","Avoid referencing variables or calling functions in the lambda","Pre-format the lambda text so the AST contains a Constant node"],"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"}