{"record":{"id":"016bcb337657f349","repo":"microsoft/semantic-kernel","slug":"unsupported-boolop-type-op-016bcb","errorCode":null,"errorMessage":"Unsupported BoolOp: {type(op)}","messagePattern":"Unsupported BoolOp: (.+?)","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/mongodb.py","lineNumber":487,"sourceCode":"                    case ast.NotEq():\n                        return {left: {\"$ne\": right}}\n                    case ast.Gt():\n                        return {left: {\"$gt\": right}}\n                    case ast.GtE():\n                        return {left: {\"$gte\": right}}\n                    case ast.Lt():\n                        return {left: {\"$lt\": right}}\n                    case ast.LtE():\n                        return {left: {\"$lte\": right}}\n                raise NotImplementedError(f\"Unsupported operator: {type(op)}\")\n            case ast.BoolOp():\n                op = node.op  # type: ignore\n                values = [self._lambda_parser(v) for v in node.values]\n                if isinstance(op, ast.And):\n                    return {\"$and\": values}\n                if isinstance(op, ast.Or):\n                    return {\"$or\": values}\n                raise NotImplementedError(f\"Unsupported BoolOp: {type(op)}\")\n            case ast.UnaryOp():\n                match node.op:\n                    case ast.Not():\n                        operand = self._lambda_parser(node.operand)\n                        return {\"$not\": operand}\n                    case ast.UAdd() | ast.USub() | ast.Invert():\n                        raise NotImplementedError(\"Unary +, -, ~ are not supported in MongoDB filters.\")\n            case ast.Attribute():\n                # Only allow attributes that are in the data model\n                if node.attr not in self.definition.storage_names:\n                    raise VectorStoreOperationException(\n                        f\"Field '{node.attr}' not in data model (storage property names are used).\"\n                    )\n                return node.attr\n            case ast.Name():\n                # Only allow names that are in the data model\n                if node.id not in self.definition.storage_names:\n                    raise VectorStoreOperationException(","sourceCodeStart":469,"sourceCodeEnd":505,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/mongodb.py#L469-L505","documentation":"The MongoDB filter lambda parser handles boolean operations (`and`, `or`) by translating them to `$and`/`$or`. This NotImplementedError is raised when the lambda contains a BoolOp whose op type is neither `ast.And` nor `ast.Or`. In standard Python the only two BoolOp types are `and` and `or`, so this error is extremely rare under normal usage but serves as a defensive guard for malformed or non-standard AST input.","triggerScenarios":"The lambda predicate contains a boolean operation node whose operator is not `and` or `or`. This is essentially unreachable under normal Python lambdas but could surface with AST manipulation, code generation tools, or corrupted lambda objects.","commonSituations":"Rare in practice. Could arise from metaprogramming or code-generation frameworks that synthesize AST nodes not produced by the standard Python compiler.","solutions":["Restructure the filter to use only standard `and` / `or` boolean combinators in the lambda.","Avoid programmatic AST construction for filter predicates; use plain Python lambdas.","Split complex boolean logic into nested `and`/`or` sub-expressions."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"import ast, inspect\ndef validate_bool_ops(func):\n    tree = ast.parse(inspect.getsource(func))\n    for node in ast.walk(tree):\n        if isinstance(node, ast.BoolOp) and not isinstance(node.op, (ast.And, ast.Or)):\n            raise ValueError(f\"Unsupported boolean operator: {type(node.op).__name__}\")","typeGuard":null,"tryCatchPattern":"try:\n    results = await collection.search(filter=my_lambda)\nexcept NotImplementedError as e:\n    if \"Unsupported BoolOp\" in str(e):\n        # rewrite using only 'and' / 'or'\n        ...","preventionTips":["Use only standard Python 'and' and 'or' in filter lambdas.","Avoid programmatic AST construction for filter predicates."],"tags":["mongodb","filter","lambda","ast","semantic-kernel"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}