{"record":{"id":"2f3e4f321021d5a6","repo":"microsoft/semantic-kernel","slug":"unsupported-constant-type-type-value","errorCode":null,"errorMessage":"Unsupported constant type: {type(value)}","messagePattern":"Unsupported constant type: (.+?)","errorType":"exception","errorClass":"VectorStoreOperationException","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/azure_ai_search.py","lineNumber":731,"sourceCode":"                        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\n\n    @override\n    def _get_score_from_result(self, result: dict[str, Any]) -> float | None:\n        return result.get(\"@search.score\")\n\n    @override\n    async def __aexit__(self, exc_type, exc_value, traceback) -> None:\n        \"\"\"Exit the context manager.\"\"\"\n        if self.managed_client:\n            await self.search_client.close()\n        if self.managed_search_index_client:\n            await self.search_index_client.close()\n","sourceCodeStart":713,"sourceCodeEnd":749,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/azure_ai_search.py#L713-L749","documentation":"Raised in the ast.Constant branch of _lambda_parser when the constant's value is not one of the handled types (str, bytes, bool, None, int, float). The parser can emit OData literals for those primitives, but any other Python type held in an ast.Constant (e.g. complex, or an enum/object that the AST represents as a constant) cannot be serialized to OData, so a VectorStoreOperationException is raised.","triggerScenarios":"Using a constant of an unsupported type in a filter lambda — e.g. lambda x: x.value == 3j (complex), or a constant that evaluates to a type the parser does not recognize. Less common in normal code, but can arise with frozen dataclasses/enums that compile into unusual constant nodes.","commonSituations":"Comparing a field against a complex number; using an object/enum instance as a literal that the AST surfaces as a non-primitive constant; edge cases from AST produced by decorators or codegen.","solutions":["Use only primitive literal types in filter comparisons: str, int, float, bool, None (and bytes for binary).","Convert enums to their underlying primitive value (e.g. MyEnum.X.value) before using in the filter.","For complex/datetime values, compare against an ISO-format string constant instead."],"exampleFix":"// before\noptions.filter = lambda x: x.color == Color.RED   # Color.RED is not a primitive\n\n// after\noptions.filter = lambda x: x.color == 'red'   # primitive str constant","handlingStrategy":"validation","validationCode":"import ast\n\ndef filter_constants_are_primitives(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.Constant):\n            assert isinstance(node.value, (str, int, float, bool, type(None), bytes)), \\\n                f\"Unsupported constant type: {type(node.value).__name__}\"\n\nfilter_constants_are_primitives(opts.filter)","typeGuard":null,"tryCatchPattern":"from semantic_kernel.exceptions import VectorStoreOperationException\ntry:\n    res = await collection.search(values=q, options=opts)\nexcept VectorStoreOperationException as e:\n    if \"Unsupported constant type\" in str(e):\n        opts.filter = lambda x: x.color == 'red'  # primitive instead of enum/object\n        res = await collection.search(values=q, options=opts)\n    raise","preventionTips":["Use only primitive literals (str, int, float, bool, None, bytes) in filter comparisons.","Convert enums to their underlying primitive value before use in a filter.","Represent datetimes as ISO-8601 strings in filter constants."],"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"}