{"record":{"id":"07c4318e69e5dcba","repo":"microsoft/semantic-kernel","slug":"call-target-node-type-type-node-func-name","errorCode":null,"errorMessage":"Call target node type '{type(node.func).__name__}' is not allowed in filter expressions.","messagePattern":"Call target node type '(.+?)' is not allowed in filter expressions\\.","errorType":"exception","errorClass":"VectorStoreOperationException","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/in_memory.py","lineNumber":307,"sourceCode":"            if node.func.attr == \"contains\":\n                if len(args) != 1:\n                    raise VectorStoreOperationException(\"Method 'contains' expects exactly one argument.\")\n                return args[0] in target\n\n            try:\n                func = getattr(target, node.func.attr)\n            except AttributeError as e:\n                raise VectorStoreOperationException(\n                    f\"Method '{node.func.attr}' is not available in filter expressions.\"\n                ) from e\n\n            if not callable(func):\n                raise VectorStoreOperationException(\n                    f\"Attribute '{node.func.attr}' is not callable in filter expressions.\"\n                )\n            return func(*args)\n\n        raise VectorStoreOperationException(\n            f\"Call target node type '{type(node.func).__name__}' is not allowed in filter expressions.\"\n        )\n\n    def _compare(self, operator_node: ast.AST, left: Any, right: Any) -> bool:\n        \"\"\"Evaluate a comparison operator.\"\"\"\n        if isinstance(operator_node, ast.Eq):\n            return left == right\n        if isinstance(operator_node, ast.NotEq):\n            return left != right\n        if isinstance(operator_node, ast.Lt):\n            return left < right\n        if isinstance(operator_node, ast.LtE):\n            return left <= right\n        if isinstance(operator_node, ast.Gt):\n            return left > right\n        if isinstance(operator_node, ast.GtE):\n            return left >= right\n        if isinstance(operator_node, ast.In):","sourceCodeStart":289,"sourceCodeEnd":325,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/in_memory.py#L289-L325","documentation":"Thrown by _eval_Call (in_memory.py:307-309) when a Call node's func is neither an ast.Name nor an ast.Attribute (e.g. calling the result of a subscript or another call). This is defense-in-depth: the parse-time Call validation (in_memory.py:796-806) rejects such constructs earlier with a different message, so this branch is only reachable if the allowlist has been subclassed/relaxed to admit chained or subscript calls without teaching the evaluator to handle them.","triggerScenarios":"Subclassing InMemoryCollection and adding ast.Subscript, ast.Call, or ast.Lambda to allowed_filter_ast_nodes so a filter like `lambda x: x[0]()` or `lambda x: (lambda y: y)(x)` passes parsing, then reaches an evaluator that cannot dispatch the call target.","commonSituations":"Extending the filter sandbox via subclassing without extending _eval_Call; importing filters from an untrusted source that the subclass is more permissive about.","solutions":["Do not relax allowed_filter_ast_nodes to permit chained/subscript/lambda call targets.","If you genuinely need such calls, override _eval_Call in your subclass to handle the extra target types safely.","Keep the parse-time Call validation intact so unsupported call shapes are rejected before evaluation."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"import ast\n\nSAFE_NODES = {\n    ast.Expression, ast.Lambda, ast.arguments, ast.arg, ast.Compare, ast.BoolOp,\n    ast.UnaryOp, ast.And, ast.Or, ast.Not, ast.Eq, ast.NotEq, ast.Lt, ast.LtE,\n    ast.Gt, ast.GtE, ast.In, ast.NotIn, ast.Is, ast.IsNot, ast.Name, ast.Load,\n    ast.Attribute, ast.Subscript, ast.Slice, ast.Constant, ast.List, ast.Tuple,\n    ast.Set, ast.Dict, ast.BinOp, ast.Add, ast.Sub, ast.Mult, ast.Div, ast.Mod,\n    ast.FloorDiv, ast.Call,\n}\n\ndef preflight_filter(expr: str, *, max_len: int = 2048, max_nodes: int = 128) -> None:\n    if len(expr) > max_len:\n        raise ValueError(\"filter too long\")\n    try:\n        tree = ast.parse(expr, mode=\"eval\")\n    except SyntaxError as e:\n        raise ValueError(f\"invalid python: {e}\") from e\n    if not (isinstance(tree, ast.Expression) and isinstance(tree.body, ast.Lambda)):\n        raise ValueError(\"filter must be a lambda expression\")\n    blocked = {\"__class__\", \"__globals__\", \"__subclasses__\", \"__builtins__\", \"__code__\"}\n    for n in ast.walk(tree):\n        if isinstance(n, ast.Attribute) and n.attr in blocked:\n            raise ValueError(f\"blocked attribute: {n.attr}\")\n        if type(n) not in SAFE_NODES:\n            raise ValueError(f\"disallowed node: {type(n).__name__}\")\n    if sum(1 for _ in ast.walk(tree)) > max_nodes:\n        raise ValueError(\"filter too complex\")\n","typeGuard":null,"tryCatchPattern":"try:\n    results = await collection.search(search_type=SearchType.VECTOR, options=opts)\nexcept VectorStoreOperationException as e:\n    logger.warning(\"filter rejected: %s\", e.__cause__ or e)\n    results = None","preventionTips":["Treat allowed_filter_ast_nodes as read-only unless you also extend the evaluator.","Run the full filter test suite after any allowlist change."],"tags":["filter","in-memory","security","semantic-kernel","evaluation"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}