microsoft/semantic-kernel · error · VectorStoreOperationException
Boolean operator '{type(node.op).__name__}' is not allowed i
Error message
Boolean operator '{type(node.op).__name__}' is not allowed in filter expressions. What it means
_eval_BoolOp handles only ast.And and ast.Or; any other operator type raises VectorStoreOperationException. In standard Python AST a BoolOp is always And or Or, so this branch is effectively unreachable through normal lambda parsing and serves purely as a defense-in-depth guard against crafted/modified AST.
Source
Thrown at python/semantic_kernel/connectors/in_memory.py:229
return result
def _eval_BoolOp(self, node: ast.BoolOp, context: Mapping[str, Any]) -> Any:
"""Evaluate boolean operators with Python short-circuit semantics."""
if isinstance(node.op, ast.And):
result = self.evaluate(node.values[0], context)
for value in node.values[1:]:
if not result:
return result
result = self.evaluate(value, context)
return result
if isinstance(node.op, ast.Or):
result = self.evaluate(node.values[0], context)
for value in node.values[1:]:
if result:
return result
result = self.evaluate(value, context)
return result
raise VectorStoreOperationException(
f"Boolean operator '{type(node.op).__name__}' is not allowed in filter expressions."
)
def _eval_UnaryOp(self, node: ast.UnaryOp, context: Mapping[str, Any]) -> Any:
"""Evaluate a unary operator."""
operand = self.evaluate(node.operand, context)
if isinstance(node.op, ast.Not):
return not operand
raise VectorStoreOperationException(
f"Unary operator '{type(node.op).__name__}' is not allowed in filter expressions."
)
def _eval_Compare(self, node: ast.Compare, context: Mapping[str, Any]) -> bool:
"""Evaluate a comparison expression."""
left = self.evaluate(node.left, context)
for operator_node, comparator in zip(node.ops, node.comparators, strict=True):
right = self.evaluate(comparator, context)
if not self._compare(operator_node, left, right):View on GitHub (pinned to c028a0c7dc)
Solutions
- Use the standard boolean operators 'and' / 'or' in filter expressions.
- Do not construct or mutate filter AST by hand; pass lambdas or string lambdas only.
Example fix
# no normal Python source triggers this; use standard operators VectorSearchOptions(filter=lambda x: x.a == 1 and x.b == 2)
Defensive patterns
Strategy: validation
Validate before calling
import ast
def uses_only_bool_ops(filter_str: str) -> None:
for node in ast.walk(ast.parse(filter_str, mode='eval')):
if isinstance(node, ast.BoolOp) and not isinstance(node.op, (ast.And, ast.Or)):
raise ValueError(f"boolean operator {type(node.op).__name__} is not allowed") Prevention
- Use only 'and' / 'or' in filter expressions.
- Do not hand-construct filter AST.
When it happens
Trigger: Not reachable via ordinary Python source; would require hand-constructed or post-processed AST with a non-standard BoolOp operator.
Common situations: Effectively none in normal use; relevant only to AST manipulation or a corrupted/custom parse pipeline.
Related errors
- AST node type '{type(node).__name__}' is not supported durin
- Use of name '{node.id}' is not allowed in filter expressions
- Dictionary unpacking is not allowed in filter expressions.
- Unary operator '{type(node.op).__name__}' is not allowed in
- Binary operator '{type(node.op).__name__}' is not allowed in
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/b0cace6172b0ec60.
Report an issue: GitHub.