{"record":{"id":"3850768a226d50b1","repo":"microsoft/semantic-kernel","slug":"constants-are-not-supported-make-sure-to-use-a-va","errorCode":null,"errorMessage":"Constants are not supported, make sure to use a value or a attribute.","messagePattern":"Constants are not supported, make sure to use a value or a attribute\\.","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/azure_ai_search.py","lineNumber":718,"sourceCode":"                raise NotImplementedError(f\"Unsupported operator: {type(op)}\")\n            case ast.BoolOp():\n                op_str = \"and\" if isinstance(node.op, ast.And) else \"or\"\n                return \"(\" + f\" {op_str} \".join([self._lambda_parser(v) for v in node.values]) + \")\"\n            case ast.UnaryOp():\n                match node.op:\n                    case ast.UAdd():\n                        return f\"+{self._lambda_parser(node.operand)}\"\n                    case ast.USub():\n                        return f\"-{self._lambda_parser(node.operand)}\"\n                    case ast.Invert():\n                        raise NotImplementedError(\"Invert operation is not supported.\")\n                    case ast.Not():\n                        return f\"not {self._lambda_parser(node.operand)}\"\n            case ast.Attribute():\n                # Support nested property chains\n                return _parse_attribute_chain(node)\n            case ast.Name():\n                raise NotImplementedError(\"Constants are not supported, make sure to use a value or a attribute.\")\n            case ast.Constant():\n                value = node.value\n                if isinstance(value, str):\n                    return \"'\" + value.replace(\"'\", \"''\") + \"'\"\n                if isinstance(value, bytes):\n                    return \"'\" + value.decode(\"utf-8\").replace(\"'\", \"''\") + \"'\"\n                if isinstance(value, bool):\n                    return str(value).lower()\n                if value is None:\n                    return \"null\"\n                if isinstance(value, (int, float)):\n                    return str(value)\n                raise VectorStoreOperationException(f\"Unsupported constant type: {type(value)}\")\n        raise NotImplementedError(f\"Unsupported AST node: {type(node)}\")\n\n    @override\n    def _get_record_from_result(self, result: dict[str, Any]) -> dict[str, Any]:\n        return result","sourceCodeStart":700,"sourceCodeEnd":736,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/azure_ai_search.py#L700-L736","documentation":"Raised in the ast.Name branch of _lambda_parser when the AST contains a bare variable reference (ast.Name) that is not part of an attribute chain. A standalone name in a filter (other than the implicit lambda-parameter root, which is skipped inside attribute chains) cannot be translated to an OData field path or value, so NotImplementedError is raised with a hint to use a value or an attribute.","triggerScenarios":"Writing a filter lambda that references a bare variable on the right-hand side that the parser encounters as an ast.Name, e.g. lambda x: x.field == threshold where 'threshold' is resolved as a Name rather than a Constant (this happens with certain AST shapes / non-literal references). Also lambda x: x == y where y is a Name.","commonSituations":"Referencing an outer-scope variable by name instead of a literal/constant in the filter; using a bare variable where the parser expects a constant value or an x.field attribute.","solutions":["Use literal constant values (numbers, strings) directly in the filter lambda instead of referencing variables by name.","Reference fields as x.field (attribute chains starting at the lambda parameter), not as bare names.","If you need a dynamic value, substitute it into the lambda as a literal before passing to the filter."],"exampleFix":"// before\nthreshold = 10\noptions.filter = lambda x: x.count > threshold   # 'threshold' is a Name\n\n// after\noptions.filter = lambda x: x.count > 10   # literal Constant","handlingStrategy":"validation","validationCode":"import ast\n\ndef filter_no_bare_names(filter_lambda) -> None:\n    tree = ast.parse(ast.getsource(filter_lambda), mode=\"exec\")\n    for node in ast.walk(tree):\n        if isinstance(node, ast.Name):\n            # only the lambda param root inside attribute chains is allowed;\n            # bare names as comparators are not\n            assert node.id == \"x\", (\n                f\"Bare name '{node.id}' is not supported; use a literal constant or x.field\"\n            )\n\nfilter_no_bare_names(opts.filter)","typeGuard":null,"tryCatchPattern":"try:\n    res = await collection.search(values=q, options=opts)\nexcept NotImplementedError as e:\n    if \"Constants are not supported\" in str(e):\n        opts.filter = lambda x: x.count > 10  # literal instead of variable ref\n        res = await collection.search(values=q, options=opts)\n    raise","preventionTips":["Use literal constants (numbers/strings) on the right-hand side of comparisons.","Reference fields as x.field attribute chains, not bare names.","Substitute dynamic values into the lambda as literals before filtering."],"tags":["filter","odata","lambda-parser","azure-ai-search"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}