microsoft/semantic-kernel · error · NotImplementedError
Unsupported constant type: {type(node.value)}
Error message
Unsupported constant type: {type(node.value)} What it means
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.
Source
Thrown at python/semantic_kernel/connectors/azure_cosmos_db.py:967
raise VectorStoreOperationException(
f"Field '{node.attr}' not in data model (storage property names are used)."
)
return f"c.{node.attr}"
case ast.Name():
# Could be a variable or constant; not supported
raise NotImplementedError("Constants or variables are not supported, use a value or attribute.")
case ast.Constant():
# Bind strings as query parameters to avoid SQL injection. Numbers and null
# cannot carry injection, so they are inlined.
if isinstance(node.value, str):
name = f"@filter_p{len(parameters)}"
parameters.append({"name": name, "value": node.value})
return name
if isinstance(node.value, (float, int)):
return str(node.value)
if node.value is None:
return "null"
raise NotImplementedError(f"Unsupported constant type: {type(node.value)}")
raise NotImplementedError(f"Unsupported AST node: {type(node)}")
return parse(node), parameters
@override
def _get_record_from_result(self, result: dict[str, Any]) -> dict[str, Any]:
return result
@override
def _get_score_from_result(self, result: dict[str, Any]) -> float | None:
return result.get(NOSQL_SCORE_PROPERTY_NAME)
@override
def _serialize_dicts_to_store_models(self, records: Sequence[dict[str, Any]], **kwargs: Any) -> Sequence[Any]:
serialized_records = []
key_field_name = self.definition.key_name
for record in records:View on GitHub (pinned to c028a0c7dc)
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.
Example fix
// before options = VectorSearchOptions(filter=lambda x: x.tags == ["a", "b"]) // after options = VectorSearchOptions(filter=lambda x: x.tag in ["a", "b"])
Defensive patterns
Strategy: validation
Validate before calling
import ast
tree = ast.parse(filter_src, mode="eval")
for node in ast.walk(tree):
if isinstance(node, ast.Constant) and not isinstance(node.value, (str, int, float, type(None))):
raise ValueError(f"Filter uses unsupported constant type: {type(node.value).__name__}") Type guard
def is_supported_constant(value) -> bool:
return isinstance(value, (str, int, float, type(None))) Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Unsupported operator: {type(op)}
- Invert operation is not supported.
- Constants or variables are not supported, use a value or att
- Field '{node.attr}' not in data model (storage property name
- Unsupported operator: {type(op)}
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/2e4e66471ce511f3.
Report an issue: GitHub.