{"record":{"id":"2e4e66471ce511f3","repo":"microsoft/semantic-kernel","slug":"unsupported-constant-type-type-node-value","errorCode":null,"errorMessage":"Unsupported constant type: {type(node.value)}","messagePattern":"Unsupported constant type: (.+?)","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/azure_cosmos_db.py","lineNumber":967,"sourceCode":"                        raise VectorStoreOperationException(\n                            f\"Field '{node.attr}' not in data model (storage property names are used).\"\n                        )\n                    return f\"c.{node.attr}\"\n                case ast.Name():\n                    # Could be a variable or constant; not supported\n                    raise NotImplementedError(\"Constants or variables are not supported, use a value or attribute.\")\n                case ast.Constant():\n                    # Bind strings as query parameters to avoid SQL injection. Numbers and null\n                    # cannot carry injection, so they are inlined.\n                    if isinstance(node.value, str):\n                        name = f\"@filter_p{len(parameters)}\"\n                        parameters.append({\"name\": name, \"value\": node.value})\n                        return name\n                    if isinstance(node.value, (float, int)):\n                        return str(node.value)\n                    if node.value is None:\n                        return \"null\"\n                    raise NotImplementedError(f\"Unsupported constant type: {type(node.value)}\")\n            raise NotImplementedError(f\"Unsupported AST node: {type(node)}\")\n\n        return parse(node), parameters\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(NOSQL_SCORE_PROPERTY_NAME)\n\n    @override\n    def _serialize_dicts_to_store_models(self, records: Sequence[dict[str, Any]], **kwargs: Any) -> Sequence[Any]:\n        serialized_records = []\n\n        key_field_name = self.definition.key_name\n        for record in records:","sourceCodeStart":949,"sourceCodeEnd":985,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/azure_cosmos_db.py#L949-L985","documentation":"Within the ast.Constant branch the translator only binds strings (as @filter_pN parameters) and inlines float, int, and None. Any other constant type — bool, bytes, complex, dict, list, tuple, set, frozenset, etc. — falls through to NotImplementedError. The restriction exists because only those primitive SQL-safe literals have a defined Cosmos SQL rendering.","triggerScenarios":"A filter lambda uses a constant of an unsupported type, most commonly a Python bool (True/False) — note bool is not matched by the int check ordering here would normally catch it, but for non-numeric literals like bytes, lists, or complex values it raises — or a list/dict literal used directly in a comparison.","commonSituations":"Filtering with x.active == True (bool), or embedding a collection literal such as x.tags == [\"a\",\"b\"] instead of using the 'in' operator, or using bytes constants.","solutions":["Convert bools to explicit handling: Cosmos SQL accepts true/false; if the translator rejects bool, rewrite using a comparison the translator supports or pass the value as an int/string.","Use the 'in' operator for membership rather than list-equality, so the translator emits ARRAY_CONTAINS.","Restrict filter constants to str, int, float, and None."],"exampleFix":"// before\noptions = VectorSearchOptions(filter=lambda x: x.tags == [\"a\", \"b\"])\n// after\noptions = VectorSearchOptions(filter=lambda x: x.tag in [\"a\", \"b\"])\n","handlingStrategy":"validation","validationCode":"import ast\ntree = ast.parse(filter_src, mode=\"eval\")\nfor node in ast.walk(tree):\n    if isinstance(node, ast.Constant) and not isinstance(node.value, (str, int, float, type(None))):\n        raise ValueError(f\"Filter uses unsupported constant type: {type(node.value).__name__}\")","typeGuard":"def is_supported_constant(value) -> bool:\n    return isinstance(value, (str, int, float, type(None)))","tryCatchPattern":null,"preventionTips":["Use only str, int, float, None as filter constants.","Use the 'in' operator for membership instead of list/tuple equality.","Avoid bool, bytes, dict, list literals in filter expressions."],"tags":["azure-cosmos-db","filter","ast","lambda"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}