mem0ai/mem0 · error · ValueError
messages must be str, dict, or list[dict], got {type(message
Error message
messages must be str, dict, or list[dict], got {type(messages).__name__} What it means
Error "messages must be str, dict, or list[dict], got {type(messages).__name__}" thrown in mem0ai/mem0.
Source
Thrown at mem0/client/main.py:213
Returns:
A dictionary containing the API response in v1.1 format.
Raises:
ValidationError: If the input data is invalid.
AuthenticationError: If authentication fails.
RateLimitError: If rate limits are exceeded.
MemoryQuotaExceededError: If memory quota is exceeded.
NetworkError: If network connectivity issues occur.
MemoryNotFoundError: If the memory doesn't exist (for updates/deletes).
"""
kwargs = {**(options.model_dump(exclude_unset=True) if options else {}), **kwargs}
# Handle different message input formats (align with OSS behavior)
if isinstance(messages, str):
messages = [{"role": "user", "content": messages}]
elif isinstance(messages, dict):
messages = [messages]
elif not isinstance(messages, list):
raise ValueError(f"messages must be str, dict, or list[dict], got {type(messages).__name__}")
kwargs = self._prepare_params(kwargs)
payload = self._prepare_payload(messages, kwargs)
response = self.client.post("/v3/memories/add/", json=payload)
response.raise_for_status()
if "metadata" in kwargs:
del kwargs["metadata"]
capture_client_event("client.add", self, {"keys": list(kwargs.keys()), "sync_type": "sync"})
return response.json()
@api_error_handler
def get(self, memory_id: str) -> Dict[str, Any]:
"""Retrieve a specific memory by ID.
Args:
memory_id: The ID of the memory to retrieve.
Returns:View on GitHub (pinned to 001c235229)
Solutions
- Pass messages as a string, a dict like {'role':'user','content':'...'}, or a list of such dicts.
When it happens
Trigger: Thrown at mem0/client/main.py:213 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15).
Data as JSON: /api/errors/02f2a16e8a23eda3.
Report an issue: GitHub.