{"record":{"id":"4e617e6ee3d27636","repo":"langchain-ai/deepagents","slug":"namespace-component-at-index-i-must-not-be-empty","errorCode":null,"errorMessage":"Namespace component at index {i} must not be empty.","messagePattern":"Namespace component at index (.+?) must not be empty\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/deepagents/deepagents/backends/store.py","lineNumber":79,"sourceCode":"\n    Returns:\n        The validated namespace tuple (unchanged).\n\n    Raises:\n        ValueError: If the namespace is empty, contains non-string elements,\n            empty strings, or strings with disallowed characters.\n    \"\"\"\n    if not namespace:\n        msg = \"Namespace tuple must not be empty.\"\n        raise ValueError(msg)\n\n    for i, component in enumerate(namespace):\n        if not isinstance(component, str):\n            msg = f\"Namespace component at index {i} must be a string, got {type(component).__name__}.\"\n            raise TypeError(msg)\n        if not component:\n            msg = f\"Namespace component at index {i} must not be empty.\"\n            raise ValueError(msg)\n        if not _NAMESPACE_COMPONENT_RE.match(component):\n            msg = (\n                f\"Namespace component at index {i} contains disallowed characters: {component!r}. \"\n                f\"Only alphanumeric characters, hyphens, underscores, dots, @, +, colons, and tildes are allowed.\"\n            )\n            raise ValueError(msg)\n\n    return namespace\n\n\nclass StoreBackend(BackendProtocol):\n    \"\"\"Backend that stores files in LangGraph's BaseStore (persistent).\n\n    Uses LangGraph's Store for persistent, cross-conversation storage.\n    Files are organized via namespaces and persist across all threads.\n\n    Files are scoped by the caller-supplied `namespace` factory (e.g. per-user\n    or per-assistant isolation).","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/deepagents/deepagents/backends/store.py#L61-L97","documentation":"Within a namespace tuple, no component may be an empty string: `_validate_namespace` raises `ValueError` for `''` elements, since empty segments would create ambiguous or colliding store keys. The check runs after the type check and before the allowed-characters regex check.","triggerScenarios":"`StoreBackend(store, namespace=('files', ''))`; joining/joining-splitting strings into components where an empty segment slips in (e.g. `''.split('/')` or filtering that keeps empty strings); optional middle segments left as empty strings instead of being dropped.","commonSituations":"Building namespaces from URL/config paths that contain empty segments; template-based namespace construction with unfilled placeholders; over-aggressive string splitting that yields `''` between delimiters.","solutions":["Filter out empty strings before constructing: `ns = tuple(c for c in raw if c)`","Replace optional empty segments with meaningful placeholders (e.g. 'default', '_')","Validate config-derived inputs upstream and reject empty values with a clear message","Centralize namespace construction in one helper that applies `str()`, emptiness, and regex checks"],"exampleFix":"// before\nns = tuple(base.split('/'))  # may contain ''\nbackend = StoreBackend(store, namespace=ns)\n\n// after\nns = tuple(seg for seg in base.split('/') if seg)\nif not ns:\n    raise ValueError('namespace resolved to nothing')\nbackend = StoreBackend(store, namespace=ns)","handlingStrategy":"validation","validationCode":"def clean_namespace(raw: str | list[str]) -> tuple[str, ...]:\n    parts = [p for p in (raw.split('/') if isinstance(raw, str) else raw) if p]\n    if not parts:\n        raise ValueError('namespace must contain at least one non-empty component')\n    return tuple(parts)","typeGuard":"def has_no_empty_components(ns) -> bool:\n    return isinstance(ns, tuple) and all(isinstance(c, str) and c for c in ns)","tryCatchPattern":"try:\n    backend = StoreBackend(store, namespace=ns)\nexcept ValueError as e:\n    ns = tuple(c for c in ns if c)\n    backend = StoreBackend(store, namespace=ns)","preventionTips":["Filter empty strings after any split/join that builds namespace components","Use explicit placeholders ('default', '_') instead of empty strings for optional segments","Validate namespaces at config load time, before backends are constructed"],"tags":["python","validation","store-backend","namespace","value-error"],"backgroundTag":"invalid-namespace","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}