mem0ai/mem0 · error · Mem0ValidationError
VALIDATION_002
VALIDATION_002
Error message
Invalid 'memory_type'. Please pass {MemoryType.PROCEDURAL.value} to create procedural memories. What it means
Raised as Mem0ValidationError (VALIDATION_002) by Memory.add() when memory_type is given and is anything other than 'procedural' (MemoryType.PROCEDURAL.value). In this SDK build, add() only accepts two cases: memory_type=None (default semantic memories) or memory_type='procedural' (workflow/skill memories tied to an agent_id). Values like 'semantic', 'episodic', or arbitrary strings are rejected because no other memory type is implemented on this path.
Source
Thrown at mem0/memory/main.py:832
LLMError: If LLM operations fail.
DatabaseError: If database operations fail.
"""
if timestamp is not None:
raise ValueError(get_temporal_feature_error_message("sync", "add", "timestamp"))
normalized_expiration_date = _normalize_expiration_date(expiration_date)
temporal_usage_notice = detect_temporal_usage_from_metadata(metadata)
processed_metadata, effective_filters = _build_filters_and_metadata(
user_id=user_id,
agent_id=agent_id,
run_id=run_id,
input_metadata=metadata,
)
if normalized_expiration_date is not None:
processed_metadata["expiration_date"] = normalized_expiration_date
if memory_type is not None and memory_type != MemoryType.PROCEDURAL.value:
raise Mem0ValidationError(
message=f"Invalid 'memory_type'. Please pass {MemoryType.PROCEDURAL.value} to create procedural memories.",
error_code="VALIDATION_002",
details={"provided_type": memory_type, "valid_type": MemoryType.PROCEDURAL.value},
suggestion=f"Use '{MemoryType.PROCEDURAL.value}' to create procedural memories."
)
if isinstance(messages, str):
messages = [{"role": "user", "content": messages}]
elif isinstance(messages, dict):
messages = [messages]
elif not isinstance(messages, list):
raise Mem0ValidationError(
message="messages must be str, dict, or list[dict]",
error_code="VALIDATION_003",
details={"provided_type": type(messages).__name__, "valid_types": ["str", "dict", "list[dict]"]},
suggestion="Convert your input to a string, dictionary, or list of dictionaries."View on GitHub (pinned to 001c235229)
Solutions
- Omit memory_type entirely for normal (semantic) memories — None is the default and valid.
- Pass exactly memory_type='procedural' when creating procedural memories, and include agent_id since procedural memories are agent-scoped.
- Import the enum and use MemoryType.PROCEDURAL.value instead of hardcoding strings.
- Catch Mem0ValidationError and surface the embedded details (provided_type vs valid_type) in your API layer.
Example fix
# before
m.add("likes tea", user_id="u1", memory_type="semantic")
# after
m.add("likes tea", user_id="u1") # semantic is the default
# procedural case:
m.add(steps, agent_id="agent1", memory_type="procedural") Defensive patterns
Strategy: validation
Validate before calling
if memory_type is not None and memory_type != "procedural":
raise ValueError("memory_type must be 'procedural' or omitted") Type guard
def is_valid_memory_type(t) -> bool:
return t is None or t == "procedural" Try / catch
from mem0.memory.utils import Mem0ValidationError
try:
m.add(msg, agent_id="a1", memory_type=memory_type)
except Mem0ValidationError as e:
if e.error_code == "VALIDATION_002":
return {"error": "invalid memory_type", "valid": "procedural"}
raise Prevention
- Omit memory_type for ordinary memories; the default is the semantic path.
- Use MemoryType.PROCEDURAL.value rather than string literals.
- Procedural memories require agent_id — pass it together with memory_type.
When it happens
Trigger: m.add(msg, user_id='u1', memory_type='semantic') — assuming an explicit type must be named; memory_type='episodic' copied from platform docs; passing MemoryType.SOME_ENUM.name instead of .value; a typo like 'procedual'.
Common situations: Writing symmetric code that always passes memory_type for clarity; porting hosted-platform examples that enumerate multiple types; enum misuse passing the enum member where a different string is expected.
Related errors
- messages is required and cannot be undefined or null. Provid
- messages array cannot be empty. Provide at least one message
- VALIDATION_001
- expiration_date must be a valid date in YYYY-MM-DD format.
- VALIDATION_003
AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15).
Data as JSON: /api/errors/44000903b2c001ef.
Report an issue: GitHub.