mem0ai/mem0 · error · ValueError
filters must contain at least one of: user_id, agent_id, run
Error message
filters must contain at least one of: user_id, agent_id, run_id. Example: filters={'user_id': 'u1'} What it means
Raised as a plain ValueError by Memory.get_all() when the filters dict contains none of user_id, agent_id, or run_id. Unlike add(), get_all() takes scoping only through its filters argument, so an empty filters dict or one containing only non-entity keys (e.g. {'category':'preference'}) is rejected — listing every memory in the store with no actor scope is not allowed in the OSS SDK.
Source
Thrown at mem0/memory/main.py:1304
# Validate and trim entity IDs in filters
effective_filters = dict(filters) if filters else {}
if "user_id" in effective_filters:
effective_filters["user_id"] = _validate_and_trim_entity_id(
effective_filters["user_id"], "user_id"
)
if "agent_id" in effective_filters:
effective_filters["agent_id"] = _validate_and_trim_entity_id(
effective_filters["agent_id"], "agent_id"
)
if "run_id" in effective_filters:
effective_filters["run_id"] = _validate_and_trim_entity_id(
effective_filters["run_id"], "run_id"
)
# Validate filters contains at least one entity ID
if not any(key in effective_filters for key in ("user_id", "agent_id", "run_id")):
raise ValueError(
"filters must contain at least one of: user_id, agent_id, run_id. "
"Example: filters={'user_id': 'u1'}"
)
limit = top_k
fetch_limit = limit if show_expired else max(limit * 4, 60)
scale_threshold_notice = detect_scale_threshold_from_top_k(top_k)
keys, encoded_ids = process_telemetry_filters(effective_filters)
capture_event(
"mem0.get_all", self, {"limit": limit, "keys": keys, "encoded_ids": encoded_ids, "sync_type": "sync"}
)
all_memories_result = self._get_all_from_vector_store(effective_filters, fetch_limit, show_expired, limit)
if scale_threshold_notice:
display_scale_threshold_notice(self, "sync", "get_all", *scale_threshold_notice)
else:View on GitHub (pinned to 001c235229)
Solutions
- Pass the scope in filters: m.get_all(filters={'user_id': 'u1'}) (or agent_id/run_id).
- Do not pass user_id as a top-level keyword to get_all — it is rejected; it must live inside filters.
- If you truly need every memory, iterate your known user/agent IDs and union the results.
- Guard in your wrapper: raise a clear error when no entity ID is available instead of calling get_all anyway.
Example fix
# before
mems = m.get_all(filters={"category": "work"})
# after
mems = m.get_all(filters={"user_id": "u1", "category": "work"}) Defensive patterns
Strategy: validation
Validate before calling
ENTITY_KEYS = ("user_id", "agent_id", "run_id")
filters = filters or {}
if not any(k in filters and filters[k] for k in ENTITY_KEYS):
raise ValueError("get_all requires user_id/agent_id/run_id inside filters") Type guard
def has_entity_filter(filters) -> bool:
return any(filters.get(k) for k in ("user_id", "agent_id", "run_id")) Prevention
- Always build filters with a scope key first: filters = {'user_id': uid} then add extras.
- Remember get_all() has no top-level user_id kwarg — filters only.
- For 'list everything', iterate known IDs rather than calling unscoped.
When it happens
Trigger: m.get_all() with no filters at all; m.get_all(filters={'category':'work'}) forgetting the user; building filters conditionally so the user_id key is dropped when a variable is None: filters={'user_id': user_id} with user_id=None still contains the key but yields None (key present passes this check but fails later trimming) — the fully empty case comes from filters={} or filters=None plus no scope; using top-level user_id= kwarg which is rejected earlier by _reject_top_level_entity_params.
Common situations: Admin dashboards intending to list 'all' memories; refactoring from search(user_id=...) positional style to the filters dict and losing the ID; multi-tenant code where the tenant key is occasionally missing.
Related errors
- Top-level entity parameters [${invalidKeys.join(", ")}] are
- Invalid ${name}: cannot be empty or whitespace-only. Provide
- Invalid ${name}: cannot contain whitespace. Provide a valid
- One of the filters: userId, agentId or runId is required!
- filters must contain at least one of: user_id, agent_id, run
AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15).
Data as JSON: /api/errors/3d08adc2c42128fb.
Report an issue: GitHub.