mem0ai/mem0 · error · ValueError

Invalid {label}: {name!r}

Error message

Invalid {label}: {name!r}

What it means

ValueError from _validate_identifier in databricks.py, applied to Databricks catalog/schema/table/index names before they are interpolated into SQL and SDK calls. The regex ^[A-Za-z_][A-Za-z0-9_]*$ requires a letter/underscore start and identifier-safe characters only; non-strings (None, int) are also rejected because of the isinstance check.

Source

Thrown at mem0/vector_stores/databricks.py:47

logger = logging.getLogger(__name__)


class MemoryResult(BaseModel):
    id: Optional[str] = None
    score: Optional[float] = None
    payload: Optional[dict] = None


excluded_keys = {"user_id", "agent_id", "run_id", "hash", "data", "created_at", "updated_at"}

# Pattern for valid SQL identifiers to prevent column name / table name injection
_VALID_SQL_IDENTIFIER = re.compile(r"^[A-Za-z_][A-Za-z0-9_]*$")


def _validate_identifier(name: str, label: str = "identifier") -> str:
    if not isinstance(name, str) or not _VALID_SQL_IDENTIFIER.match(name):
        raise ValueError(f"Invalid {label}: {name!r}")
    return name


class Databricks(VectorStoreBase):
    def __init__(
        self,
        workspace_url: str,
        access_token: Optional[str] = None,
        client_id: Optional[str] = None,
        client_secret: Optional[str] = None,
        azure_client_id: Optional[str] = None,
        azure_client_secret: Optional[str] = None,
        endpoint_name: str = None,
        catalog: str = None,
        schema: str = None,
        table_name: str = None,
        collection_name: str = "mem0",
        index_type: str = "DELTA_SYNC",

View on GitHub (pinned to 001c235229)

Solutions

  1. Use identifier-safe names: letters, digits, underscores, starting with a letter or underscore.
  2. Ensure all name components are set (not None) and pass them as strings; check env vars before construction.
  3. Sanitize dynamic fragments: re.sub(r'[^A-Za-z0-9_]', '_', part).

Example fix

# before
Databricks(workspace_url=..., catalog=None, ...)  # or table "my-table" -> ValueError

# after
Databricks(workspace_url=..., catalog="main", table_name="mem0_memories", ...)
Defensive patterns

Strategy: validation

Validate before calling

import re
_SQL_IDENT = re.compile(r"^[A-Za-z_][A-Za-z0-9_]*$")

def databricks_name(label: str, value) -> str:
    if not isinstance(value, str) or not _SQL_IDENT.match(value):
        raise ValueError(f"{label} must be a SQL identifier, got {value!r}")
    return value

catalog = databricks_name("catalog", os.environ["DBX_CATALOG"])
table = databricks_name("table_name", os.environ.get("DBX_TABLE", "mem0_memories"))

Type guard

def is_sql_identifier(name) -> bool:
    import re
    return isinstance(name, str) and bool(re.match(r"^[A-Za-z_][A-Za-z0-9_]*$", name))

Prevention

When it happens

Trigger: Constructing the Databricks store with fully_qualified_index_name/table name parts containing hyphens, dots outside the expected splitting, quotes, or None (e.g. missing catalog env var). The validator runs on each identifier component during __init__ before any workspace call.

Common situations: Workspace/table names copied from the Databricks UI that contain hyphens; environment variables for catalog/schema not set (yielding None); names built by concatenating user input with separators like '-'.

Related errors


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