mem0ai/mem0 · critical · ValueError
MEM0_TELEMETRY must be a boolean value.
Error message
MEM0_TELEMETRY must be a boolean value.
What it means
Raised at import time of mem0.memory.telemetry when the MEM0_TELEMETRY environment variable, after the str-to-bool conversion, is not a bool. In practice os.environ.get() always returns a str (or the default 'True'), and any string is coerced via `value.lower() in ('true','1','yes')`, so this ValueError is effectively unreachable through the environment variable — it fires only if MEM0_TELEMETRY is programmatically set to a non-str/non-bool object before import (e.g. monkeypatching or mutating os.environ with an int). Because it triggers on import, it breaks every mem0 import, not just telemetry calls.
Source
Thrown at mem0/memory/telemetry.py:23
import random
import sys
import threading
from posthog import Posthog
import mem0
from mem0.memory.setup import get_or_create_user_id
MEM0_TELEMETRY = os.environ.get("MEM0_TELEMETRY", "True")
PROJECT_API_KEY = "phc_hgJkUVJFYtmaJqrvf6CYN67TIQ8yhXAkWzUn9AMU4yX"
HOST = "https://us.i.posthog.com"
FEATURE_FLAGS_REQUEST_TIMEOUT_SECONDS = 0.5
if isinstance(MEM0_TELEMETRY, str):
MEM0_TELEMETRY = MEM0_TELEMETRY.lower() in ("true", "1", "yes")
if not isinstance(MEM0_TELEMETRY, bool):
raise ValueError("MEM0_TELEMETRY must be a boolean value.")
logging.getLogger("posthog").setLevel(logging.CRITICAL + 1)
logging.getLogger("urllib3").setLevel(logging.CRITICAL + 1)
_logger = logging.getLogger(__name__)
# Default sampling rate for hot-path OSS events. Lifecycle events always fire at 100%.
# Override via MEM0_TELEMETRY_SAMPLE_RATE env var.
_DEFAULT_SAMPLE_RATE = 0.1
def _parse_sample_rate(raw):
"""Parse MEM0_TELEMETRY_SAMPLE_RATE env var. Never raises."""
try:
value = float(raw)
except (TypeError, ValueError):
_logger.debug("MEM0_TELEMETRY_SAMPLE_RATE %r is not a number, defaulting to %s", raw, _DEFAULT_SAMPLE_RATE)
return _DEFAULT_SAMPLE_RATEView on GitHub (pinned to 001c235229)
Solutions
- Set MEM0_TELEMETRY as a plain string ('true'/'false', '1'/'0', 'yes'/'no'); any other string silently disables telemetry rather than raising
- If you are patching in tests, patch the module attribute after import, or use string values in os.environ
- Remove programmatic writes of non-string values into os.environ before importing mem0
Example fix
# before os.environ["MEM0_TELEMETRY"] = 1 # non-string -> ValueError at import import mem0 # after os.environ["MEM0_TELEMETRY"] = "1" # plain string import mem0
Defensive patterns
Strategy: validation
Validate before calling
import os
val = os.environ.get("MEM0_TELEMETRY", "True")
assert isinstance(val, str), "MEM0_TELEMETRY must be a string env value" Prevention
- Always set env vars as strings, including in test monkeypatching
- Patch module attributes after import rather than injecting typed env values
- Know that invalid strings (e.g. 'off') silently disable telemetry instead of raising
When it happens
Trigger: Patching mem0.memory.telemetry.MEM0_TELEMETRY or os.environ['MEM0_TELEMETRY'] with a non-string value (e.g. 1 as int, or a Mock) before importing mem0; test harnesses that inject raw values into os.environ; exotic environments that expose env values as non-strings.
Common situations: Test suites monkeypatching telemetry settings aggressively; CI configurations that inject typed values into the environment; developers surprised that any invalid-looking value like MEM0_TELEMETRY=off does NOT raise (it silently becomes False) while a non-string type does.
Related errors
- Cohere API key is required. Set COHERE_API_KEY environment v
- Zero Entropy API key is required. Set ZERO_ENTROPY_API_KEY e
- PGVector requires either connectionString or ${missingFields
- Pinecone API key required: pass apiKey or set PINECONE_API_K
- Cohere API key is required. Set COHERE_API_KEY environment v
AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15).
Data as JSON: /api/errors/e19cc5db174a319c.
Report an issue: GitHub.