mem0ai/mem0 · error · ValueError

Filter value for {key!r} must be str, int, float, or bool, g

Error message

Filter value for {key!r} must be str, int, float, or bool, got {type(value).__name__}

What it means

Neptune Analytics filter values are interpolated into openCypher literals, so only scalars (str, int, float, bool) are accepted. This error fires when a filter value is a list, dict, None-with-type, or any other object, because such values cannot be rendered as a safe Cypher literal and could enable injection or produce malformed queries.

Source

Thrown at mem0/vector_stores/neptune_analytics.py:26

try:
    from langchain_aws import NeptuneAnalyticsGraph
except ImportError:
    raise ImportError("langchain_aws is not installed. Please install it using pip install langchain_aws")

from mem0.vector_stores.base import VectorStoreBase

logger = logging.getLogger(__name__)

_SAFE_FILTER_KEY = re.compile(r"^[a-zA-Z_~][a-zA-Z0-9_]*$")
_VALID_IDENTIFIER = re.compile(r"^[A-Za-z_][A-Za-z0-9_]*$")


def _validate_filter(key: str, value: Any) -> None:
    if not isinstance(key, str) or not _SAFE_FILTER_KEY.match(key):
        raise ValueError(f"Invalid filter key: {key!r}")
    if not isinstance(value, (str, int, float, bool)):
        raise ValueError(
            f"Filter value for {key!r} must be str, int, float, or bool, "
            f"got {type(value).__name__}"
        )


def _escape_cypher(value: str) -> str:
    return value.replace("\\", "\\\\").replace("'", "\\'")

class OutputData(BaseModel):
    id: Optional[str]  # memory id
    score: Optional[float]  # distance
    payload: Optional[Dict]  # metadata


class NeptuneAnalyticsVector(VectorStoreBase):
    """
    Neptune Analytics vector store implementation for Mem0.
    

View on GitHub (pinned to 001c235229)

Solutions

  1. Split multi-value filters into one of: run one search per value and merge results client-side
  2. Keep every filter value a scalar; serialize complex values to a string before filtering
  3. Validate the filters dict shape before calling search (see guard below)

Example fix

// before
filters = {"user_id": ["a", "b"]}

// after
results = [r for v in ["a", "b"] for r in store.search(query, vec, top_k, {"user_id": v})]
Defensive patterns

Strategy: type-guard

Validate before calling

def assert_scalar_filters(filters: dict) -> None:
    bad = [k for k, v in (filters or {}).items() if not isinstance(v, (str, int, float, bool))]
    if bad:
        raise TypeError(f"non-scalar filter values for {bad}")

assert_scalar_filters(filters)
store.search(query, vector, top_k, filters=filters)

Type guard

def is_scalar_filters(filters: dict) -> bool:
    return all(isinstance(v, (str, int, float, bool)) for v in (filters or {}).values())

Try / catch

try:
    store.search(q, vec, filters=filters)
except ValueError as e:
    if "must be str, int, float, or bool" in str(e):
        filters = {k: v for k, v in filters.items() if isinstance(v, (str, int, float, bool))}
        store.search(q, vec, filters=filters)
    else:
        raise

Prevention

When it happens

Trigger: filters={"user_id": ["a","b"]} (list, no $in support in this backend), {"meta": {"k":1}} (dict), or a custom object passed as a value on the Neptune Analytics backend.

Common situations: Porting multi-value filters from Qdrant-style backends that accept lists; forwarding untyped JSON payloads as filters; None values that bypass the earlier truthiness handling.

Related errors


AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15). Data as JSON: /api/errors/30ca70f67be8845d. Report an issue: GitHub.