microsoft/semantic-kernel · error · VectorStoreOperationException

Attribute '{node.attr}' is not available in filter expressio

Error message

Attribute '{node.attr}' is not available in filter expressions.

What it means

After clearing the blocklist, _eval_Attribute resolves the attribute via getattr(value, node.attr). If the underlying record does not have that attribute, AttributeError is raised and re-wrapped as VectorStoreOperationException. This is the common real-world case (distinct from the 1310 blocklist): the filter names a field that simply is not present on the record.

Source

Thrown at python/semantic_kernel/connectors/in_memory.py:168

        return node.value

    def _eval_Name(self, node: ast.Name, context: Mapping[str, Any]) -> Any:
        """Evaluate a variable reference."""
        if node.id not in context:
            raise VectorStoreOperationException(f"Use of name '{node.id}' is not allowed in filter expressions.")
        return context[node.id]

    def _eval_Attribute(self, node: ast.Attribute, context: Mapping[str, Any]) -> Any:
        """Evaluate an attribute access."""
        if node.attr in self._blocked_attributes:
            raise VectorStoreOperationException(
                f"Access to attribute '{node.attr}' is not allowed in filter expressions."
            )
        value = self.evaluate(node.value, context)
        try:
            return ReadOnlyAttributeDict._wrap_value(getattr(value, node.attr))
        except AttributeError as e:
            raise VectorStoreOperationException(
                f"Attribute '{node.attr}' is not available in filter expressions."
            ) from e

    def _eval_Subscript(self, node: ast.Subscript, context: Mapping[str, Any]) -> Any:
        """Evaluate an index or slice operation."""
        value = self.evaluate(node.value, context)
        slice_value = self.evaluate(node.slice, context)
        try:
            return ReadOnlyAttributeDict._wrap_value(value[slice_value])
        except Exception as e:
            raise VectorStoreOperationException(f"Error evaluating subscript access: {e}") from e

    def _eval_Slice(self, node: ast.Slice, context: Mapping[str, Any]) -> slice:
        """Evaluate a slice node."""
        lower = self._evaluate_optional(node.lower, context)
        upper = self._evaluate_optional(node.upper, context)
        step = self._evaluate_optional(node.step, context)
        return slice(lower, upper, step)

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Use the exact field name declared in the data model definition.
  2. Use a safe accessor such as x.get('field') (get is in the allowed function list) or guard with 'field' in x.
  3. Validate filter field names against collection.definition.names before searching.

Example fix

# before
await collection.search(vector=[...], options=VectorSearchOptions(filter=lambda x: x.titl == 'foo'))  # typo -> [1311]

# after
await collection.search(vector=[...], options=VectorSearchOptions(filter=lambda x: x.title == 'foo'))
# or safe access: lambda x: x.get('title') == 'foo'
Defensive patterns

Strategy: validation

Validate before calling

def validate_filter_fields(filter_str: str, valid_field_names: set[str]) -> None:
    import ast
    for node in ast.walk(ast.parse(filter_str, mode='eval')):
        if isinstance(node, ast.Attribute) and node.attr not in valid_field_names and node.attr not in {
            'get','keys','values','items','contains','lower','upper','strip','startswith','endswith',
        }:
            raise ValueError(f"filter references unknown field '{node.attr}'")

Try / catch

from semantic_kernel.exceptions import VectorStoreOperationException
try:
    await collection.search(vector=[...], options=opts)
except VectorStoreOperationException as ex:
    if 'is not available in filter expressions' in str(ex):
        # switch to x.get('field') or fix the field name
        ...
    raise

Prevention

When it happens

Trigger: A filter like lambda x: x.titl == 'foo' (typo), or lambda x: x.nonexistent where the record dict/object has no such key. Records use AttributeDict/ReadOnlyAttributeDict, so missing keys surface as AttributeError here.

Common situations: Field-name typo; field renamed in the data model; filter written against a different schema; optional fields absent on some records; mixing attribute and dict access styles.

Related errors


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