{"record":{"id":"9f8812c056ecb13c","repo":"langflow-ai/langflow","slug":"knowledge-base-kb-name-already-exists","errorCode":null,"errorMessage":"Knowledge base '{kb_name}' already exists","messagePattern":"Knowledge base '(.+?)' already exists","errorType":"http","errorClass":"HTTPException","httpStatus":409,"severity":"error","filePath":"src/backend/base/langflow/api/v1/knowledge_bases.py","lineNumber":739,"sourceCode":"        if not kb_name or len(kb_name) < MIN_KB_NAME_LENGTH:\n            raise HTTPException(status_code=400, detail=\"Knowledge base name must be at least 3 characters\")\n\n        # Security: resolve paths and validate containment to prevent path traversal attacks.\n        # A crafted kb_name like \"../victim/evil\" or an absolute path like \"/tmp/evil\" must be\n        # rejected before any directory is created.\n        kb_user_path = (kb_root_path / kb_user).resolve()\n        kb_path = (kb_user_path / kb_name).resolve()\n        # The username also roots the path, so it must be contained within the KB root\n        # too (a username with \"..\" would otherwise escape it before mkdir).\n        _validate_kb_path_containment(kb_root_path.resolve(), kb_user_path, kb_name, kb_user)\n        _validate_kb_path_containment(kb_user_path, kb_path, kb_name, kb_user)\n\n        # Check both durable DB state and legacy disk state. During\n        # expand/contract rollout a KB row can exist even if its local\n        # sidecar directory was cleaned up out of band.\n        existing_record = await knowledge_base_service.get_by_user_and_name(current_user.id, kb_name)\n        if existing_record is not None:\n            raise HTTPException(status_code=409, detail=f\"Knowledge base '{kb_name}' already exists\")\n        if kb_path.exists():\n            # No DB row but a directory survives.  Two paths fork here:\n            # the dir is a leftover from a previous failed delete (carries\n            # the .kb_deleted sentinel) -- in which case the user clearly\n            # wants to reuse the name -- vs. a legitimate orphan from a\n            # legacy export.  Only the sentinel case is safe to repurpose.\n            if KBStorageHelper.is_kb_dir_deleted(kb_path):\n                raise HTTPException(\n                    status_code=409,\n                    detail=(\n                        f\"Knowledge base '{kb_name}' was recently deleted but its on-disk files \"\n                        \"are still being released by another process. Restart the server (or wait \"\n                        \"for the lock to clear) before recreating it with the same name.\"\n                    ),\n                )\n            raise HTTPException(status_code=409, detail=f\"Knowledge base '{kb_name}' already exists\")\n\n        # Create KB directory.  Clear any leftover sentinel just in case","sourceCodeStart":721,"sourceCodeEnd":757,"githubUrl":"https://github.com/langflow-ai/langflow/blob/976ec789d2886a86de109c044d089d68e96c9a35/src/backend/base/langflow/api/v1/knowledge_bases.py#L721-L757","documentation":"Error \"Knowledge base '{kb_name}' already exists\" thrown in langflow-ai/langflow.","triggerScenarios":"Occurs when creating a knowledge base with a name that already exists for the current user.","commonSituations":"See trigger scenarios.","solutions":["Choose a different name, or delete the existing knowledge base first."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"976ec789d2886a86de109c044d089d68e96c9a35","analyzedAt":"2026-08-14T18:23:12.227Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}