mem0ai/mem0 · error · ValueError
Both 'username' and 'password' must be provided together for
Error message
Both 'username' and 'password' must be provided together for authentication
What it means
Raised by the Cassandra vector store config when username and password are partially supplied. Cassandra auth in mem0 is all-or-nothing: either both credentials are set (RoleBasedAuthenticator) or both are absent (no auth). Supplying exactly one is treated as a configuration bug.
Source
Thrown at mem0/configs/vector_stores/cassandra.py:38
None,
description="Path to secure connect bundle for DataStax Astra DB"
)
protocol_version: int = Field(4, description="CQL protocol version")
load_balancing_policy: Optional[Any] = Field(
None,
description="Custom load balancing policy object"
)
@model_validator(mode="before")
@classmethod
def check_auth(cls, values: Dict[str, Any]) -> Dict[str, Any]:
"""Validate authentication parameters."""
username = values.get("username")
password = values.get("password")
# Both username and password must be provided together or not at all
if (username and not password) or (password and not username):
raise ValueError(
"Both 'username' and 'password' must be provided together for authentication"
)
return values
@model_validator(mode="before")
@classmethod
def check_connection_config(cls, values: Dict[str, Any]) -> Dict[str, Any]:
"""Validate connection configuration."""
secure_connect_bundle = values.get("secure_connect_bundle")
contact_points = values.get("contact_points")
# Either secure_connect_bundle or contact_points must be provided
if not secure_connect_bundle and not contact_points:
raise ValueError(
"Either 'contact_points' or 'secure_connect_bundle' must be provided"
)
View on GitHub (pinned to 001c235229)
Solutions
- Provide both 'username' and 'password' together in the config
- If the cluster has no authentication, remove both keys entirely
- Check that the environment/template supplying the credentials actually populates both values (log their presence, never their content)
- Default both to None in code when either is missing so the pair stays consistent
Example fix
# before CassandraConfig(contact_points=["h"], username="cassandra") # after CassandraConfig(contact_points=["h"], username="cassandra", password=os.environ["CASSANDRA_PASSWORD"])
Defensive patterns
Strategy: validation
Validate before calling
def validate_cassandra_auth(cfg: dict) -> None:
u, p = bool(cfg.get("username")), bool(cfg.get("password"))
if u != p:
raise RuntimeError("Cassandra username and password must be provided together or both omitted") Type guard
def cassandra_auth_pair_ok(cfg: dict) -> bool:
return bool(cfg.get("username")) == bool(cfg.get("password")) Try / catch
from pydantic import ValidationError
try:
CassandraConfig(**cfg)
except ValidationError as e:
if "must be provided together" in str(e):
# either fill the missing half or drop both, then retry
... Prevention
- Source both credentials from one secret-fetch so they succeed or fail together
- Check secret presence (not values) in logs before building config
- When disabling auth, remove both keys in the same commit
When it happens
Trigger: Creating CassandraConfig with 'username' but no 'password', or 'password' but no 'username'. Falsy-vs-truthy asymmetry: one key present with a non-empty value while the other is missing/None/empty triggers it.
Common situations: Secrets loaded from different env vars where one is unset (CASSANDRA_USER set, CASSANDRA_PASSWORD missing in CI); trimming a password to empty string via a bad .strip() or templating step; switching a cluster from auth to no-auth and removing only one key.
Understand the failure class
- Authentication and authorization failures — expired tokens, bad credentials, and missing scopes.
Related errors
- Either 'password' must be provided or 'use_azure_credential'
- Either 'contact_points' or 'secure_connect_bundle' must be p
- Extra fields not allowed: {', '.join(extra_fields)}. Please
- Either access_token or both client_id/client_secret or azure
- Either api_key or user/password must be provided
AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15).
Data as JSON: /api/errors/051986ef8add9b1e.
Report an issue: GitHub.