microsoft/semantic-kernel · error · NotImplementedError
Only constant values are supported on the right side.
Error message
Only constant values are supported on the right side.
What it means
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.
Source
Thrown at python/semantic_kernel/connectors/_search_shared.py:40
@override
def visit_Lambda(self, node):
self.visit(node.body)
@override
def visit_Compare(self, node):
# Only support x.FIELD == VALUE
if not (isinstance(node.left, ast.Attribute) and isinstance(node.left.value, ast.Name)):
raise NotImplementedError("Left side must be x.FIELD.")
field = node.left.attr
if not (len(node.ops) == 1 and isinstance(node.ops[0], ast.Eq)):
raise NotImplementedError("Only == comparisons are supported.")
right = node.comparators[0]
if isinstance(right, ast.Constant):
if right.value is None:
raise NotImplementedError("None values are not supported.")
value = str(right.value)
else:
raise NotImplementedError("Only constant values are supported on the right side.")
if field not in self.valid_parameters:
raise ValueError(f"Field '{field}' is not supported.")
self.filters.append({field: quote_plus(value)})
@override
def visit_BoolOp(self, node):
if not isinstance(node.op, ast.And):
raise NotImplementedError("Only 'and' of == comparisons is supported.")
for v in node.values:
self.visit(v)
View on GitHub (pinned to c028a0c7dc)
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).
Example fix
// before target = "news" lambda x: x.category == target # 'target' is a Name, not a Constant // after target = "news" lambda x: x.category == "news" # literal inlined; or pre-format the lambda text
Defensive patterns
Strategy: validation
Validate before calling
import ast
node = ast.parse(filter_src, mode='eval').body
def check_const(n):
if isinstance(n, ast.Compare):
assert isinstance(n.comparators[0], ast.Constant), 'right side must be a constant'
if isinstance(n, ast.BoolOp):
for v in n.values: check_const(v)
check_const(node.body) Type guard
def rhs_is_constant(node: ast.Compare) -> bool:
return isinstance(node.comparators[0], ast.Constant) Prevention
- 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
When it happens
Trigger: 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`.
Common situations: Referencing an outer variable or calling a helper in the lambda; assuming the closure is evaluated.
Related errors
- Left side must be x.FIELD.
- Only == comparisons are supported.
- None values are not supported.
- Only 'and' of == comparisons is supported.
- Field '{field}' is not supported.
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/5b477fbc50967f6b.
Report an issue: GitHub.