{"record":{"id":"4960deabf91f86f9","repo":"mem0ai/mem0","slug":"invalid-label-name-only-letters-digits-an-4960de","errorCode":null,"errorMessage":"Invalid {label} '{name}': only letters, digits, and underscores are allowed, must start with a letter or underscore, and be at most 128 characters.","messagePattern":"Invalid (.+?) '(.+?)': only letters, digits, and underscores are allowed, must start with a letter or underscore, and be at most 128 characters\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"mem0/vector_stores/cassandra.py","lineNumber":28,"sourceCode":"try:\n    from cassandra.auth import PlainTextAuthProvider\n    from cassandra.cluster import Cluster\nexcept ImportError:\n    raise ImportError(\n        \"Apache Cassandra vector store requires cassandra-driver. \"\n        \"Please install it using 'pip install cassandra-driver'\"\n    )\n\nfrom mem0.vector_stores.base import VectorStoreBase\n\nlogger = logging.getLogger(__name__)\n\n_SAFE_IDENTIFIER_RE = re.compile(r'^[a-zA-Z_][a-zA-Z0-9_]{0,127}$')\n\n\ndef _validate_identifier(name: str, label: str = \"identifier\") -> str:\n    if not _SAFE_IDENTIFIER_RE.match(name):\n        raise ValueError(\n            f\"Invalid {label} '{name}': only letters, digits, and underscores are allowed, \"\n            \"must start with a letter or underscore, and be at most 128 characters.\"\n        )\n    return name\n\n\nclass OutputData(BaseModel):\n    id: Optional[str]\n    score: Optional[float]\n    payload: Optional[dict]\n\n\nclass CassandraDB(VectorStoreBase):\n    def __init__(\n        self,\n        contact_points: List[str],\n        port: int = 9042,\n        username: Optional[str] = None,","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0/vector_stores/cassandra.py#L10-L46","documentation":"ValueError from the module-level _validate_identifier helper in cassandra.py, used for keyspace and table names before any CQL is executed. It enforces ^[a-zA-Z_][a-zA-Z0-9_]{0,127}$: must start with a letter or underscore, only letters/digits/underscores after that, and at most 128 characters. This blocks CQL injection and invalid identifiers before they reach the cluster.","triggerScenarios":"Constructing CassandraDB with a keyspace or table name containing a hyphen (my-keys), a dot (my.keyspace), a leading digit (2keys), an empty string, or longer than 128 chars. _validate_identifier is called in __init__ for both keyspace and collection/table arguments.","commonSituations":"Deriving keyspace/table names from user IDs, tenant names, or hostnames that contain hyphens/dots; copying a keyspace name from a CQL shell that quotes it with double quotes (quoting is what allows special chars in CQL, but this client forbids them).","solutions":["Rename the keyspace/collection to match the identifier rule: letters, digits, underscores only, starting with a letter or underscore, <=128 chars.","If the name is dynamic, sanitize it: re.sub(r'[^A-Za-z0-9_]', '_', name) and truncate to 128.","Map unfriendly external identifiers to safe internal ones (lookup table or hash suffix) instead of passing them through."],"exampleFix":"# before\nCassandraDB(keyspace=\"my-keys\", table=\"mem0\", ...)  # ValueError\n\n# after\nCassandraDB(keyspace=\"my_keys\", table=\"mem0\", ...)","handlingStrategy":"validation","validationCode":"import re\n_IDENT = re.compile(r\"^[a-zA-Z_][a-zA-Z0-9_]{0,127}$\")\n\ndef safe_cassandra_name(name: str, fallback: str = \"mem0\") -> str:\n    if not isinstance(name, str) or not _IDENT.match(name):\n        cleaned = re.sub(r\"[^A-Za-z0-9_]\", \"_\", str(name))[:120]\n        cleaned = re.sub(r\"^[0-9]+\", \"\", cleaned) or fallback\n        return cleaned.ljust(1, \"_\") if not cleaned else cleaned\n    return name\n\nkeyspace = safe_cassandra_name(tenant_id)","typeGuard":"def is_safe_cassandra_identifier(name) -> bool:\n    import re\n    return isinstance(name, str) and bool(re.match(r\"^[a-zA-Z_][a-zA-Z0-9_]{0,127}$\", name))","tryCatchPattern":null,"preventionTips":["Never derive keyspace/table names verbatim from hostnames, emails, or user IDs.","Apply the sanitize helper at the API boundary where tenant names enter the system.","Prefer a fixed keyspace with per-tenant collection/table prefixes that you control."],"tags":["cassandra","validation","identifier","injection-guard"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}