microsoft/semantic-kernel · error · VectorStoreOperationException

Field '{node.attr}' not in data model (storage property name

Error message

Field '{node.attr}' not in data model (storage property names are used).

What it means

When the AST translator encounters an attribute access (e.g. x.field_name), it validates that the attribute name is a known storage property name in the data model definition before emitting c.<field>. If node.attr is not in self.definition.storage_names it raises a VectorStoreOperationException. This protects against generating SQL that references a non-existent column and stops SQL-injection-shaped field names early.

Source

Thrown at python/semantic_kernel/connectors/azure_cosmos_db.py:949

                    raise NotImplementedError(f"Unsupported operator: {type(op)}")
                case ast.BoolOp():
                    op_str = "AND" if isinstance(node.op, ast.And) else "OR"
                    return "(" + f" {op_str} ".join([parse(v) for v in node.values]) + ")"
                case ast.UnaryOp():
                    match node.op:
                        case ast.Not():
                            return f"NOT ({parse(node.operand)})"
                        case ast.UAdd():
                            return f"+{parse(node.operand)}"
                        case ast.USub():
                            return f"-{parse(node.operand)}"
                        case ast.Invert():
                            raise NotImplementedError("Invert operation is not supported.")
                    raise NotImplementedError(f"Unsupported unary operator: {type(node.op)}")
                case ast.Attribute():
                    # Cosmos DB: c.field_name
                    if node.attr not in self.definition.storage_names:
                        raise VectorStoreOperationException(
                            f"Field '{node.attr}' not in data model (storage property names are used)."
                        )
                    return f"c.{node.attr}"
                case ast.Name():
                    # Could be a variable or constant; not supported
                    raise NotImplementedError("Constants or variables are not supported, use a value or attribute.")
                case ast.Constant():
                    # Bind strings as query parameters to avoid SQL injection. Numbers and null
                    # cannot carry injection, so they are inlined.
                    if isinstance(node.value, str):
                        name = f"@filter_p{len(parameters)}"
                        parameters.append({"name": name, "value": node.value})
                        return name
                    if isinstance(node.value, (float, int)):
                        return str(node.value)
                    if node.value is None:
                        return "null"
                    raise NotImplementedError(f"Unsupported constant type: {type(node.value)}")

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Use the exact storage property name that the data model declares; check self.definition.storage_names (or the field's storage_name) for the correct spelling.
  2. Declare the missing field in the VectorStoreRecordDefinition so it becomes a valid filterable attribute.
  3. Fix typos in the lambda attribute to match the model field name exactly.

Example fix

// before
# data model stores the text as 'content', not 'description'
options = VectorSearchOptions(filter=lambda x: x.description == "news")
// after
options = VectorSearchOptions(filter=lambda x: x.content == "news")
Defensive patterns

Strategy: validation

Validate before calling

valid = set(store.definition.storage_names)
# before searching:
for node in ast.walk(ast.parse(filter_src, mode="eval")):
    if isinstance(node, ast.Attribute) and node.attr not in valid:
        raise ValueError(f"Filter references unknown field: {node.attr}")

Type guard

def is_known_field(store, attr: str) -> bool:
    return attr in store.definition.storage_names

Prevention

When it happens

Trigger: A filter lambda references a field by its Python/property name when the data model stores it under a different storage_name, or references a field that simply does not exist on the model, or a typo in the attribute name.

Common situations: The data model uses an alias (e.g. Python attr 'description' stored as 'desc') and the filter uses the wrong name; or you filter on a field that exists in the source dict but was not declared in the VectorStoreRecordDefinition fields.

Related errors


AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13). Data as JSON: /api/errors/9e5ea25cc9c78c47. Report an issue: GitHub.