{"record":{"id":"1b00a1fe0a0dceb4","repo":"microsoft/semantic-kernel","slug":"field-node-id-not-in-data-model-storage-prope-1b00a1","errorCode":null,"errorMessage":"Field '{node.id}' not in data model (storage property names are used).","messagePattern":"Field '(.+?)' not in data model \\(storage property names are used\\)\\.","errorType":"exception","errorClass":"VectorStoreOperationException","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/mongodb.py","lineNumber":505,"sourceCode":"                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(\n                        f\"Field '{node.id}' not in data model (storage property names are used).\"\n                    )\n                return node.id\n            case ast.Constant():\n                return node.value\n        raise NotImplementedError(f\"Unsupported AST node: {type(node)}\")\n\n    @override\n    def _get_record_from_result(self, result: dict[str, Any]) -> dict[str, Any]:\n        return result\n\n    @override\n    def _get_score_from_result(self, result: dict[str, Any]) -> float | None:\n        return result.get(MONGODB_SCORE_FIELD)\n\n    @override\n    async def __aexit__(self, exc_type, exc_value, traceback) -> None:\n        \"\"\"Exit the context manager.\"\"\"","sourceCodeStart":487,"sourceCodeEnd":523,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/mongodb.py#L487-L523","documentation":"When the MongoDB filter lambda parser encounters a bare Name node (e.g. using a variable or field reference as `field` instead of `x.field`), it validates that the name exists in the data model's `storage_names`. This VectorStoreOperationException fires when the name does not match any storage property. This guards against referencing undefined fields or variables that are not part of the data model.","triggerScenarios":"The filter lambda references a bare name (not an attribute access) that is not in the data model storage names, for example `lambda x: my_field == 1` where `my_field` is neither a data model field nor prefixed with the lambda parameter.","commonSituations":"Developer forgets to prefix the field with the lambda parameter (e.g. writes `field` instead of `x.field`). Developer references a local variable or constant by name inside the lambda. Storage name differs from the referenced name.","solutions":["Ensure every field reference in the lambda uses attribute-access form `x.field_name` with the lambda parameter prefix.","Verify the referenced name matches a storage name in the VectorStoreRecordDefinition.","Use constants via ast.Constant (literal values) rather than bare variable names inside the lambda."],"exampleFix":"// before (bare name 'status' instead of attribute access)\ncollection.search(filter=lambda x: status == \"active\")\n// after\ncollection.search(filter=lambda x: x.status == \"active\")","handlingStrategy":"validation","validationCode":"def validate_filter_names(func, storage_names: set[str]):\n    import ast, inspect\n    tree = ast.parse(inspect.getsource(func))\n    for node in ast.walk(tree):\n        if isinstance(node, ast.Name) and node.id not in storage_names:\n            # bare name not in data model — likely a missing 'x.' prefix\n            raise ValueError(f\"Name '{node.id}' not in data model; did you forget the lambda parameter prefix?\")","typeGuard":null,"tryCatchPattern":"try:\n    results = await collection.search(filter=my_lambda)\nexcept VectorStoreOperationException as e:\n    if \"not in data model\" in str(e):\n        # prefix all field references with the lambda parameter (e.g. x.field)\n        ...","preventionTips":["Always prefix field references in the lambda with the parameter name (e.g. x.field, not field).","Use only literal constants for comparison values, not bare variable names.","Validate field names against definition.storage_names before querying."],"tags":["mongodb","filter","data-model","lambda","semantic-kernel"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}