{"record":{"id":"4ecb3dad0c660fa6","repo":"langflow-ai/langflow","slug":"error-listing-metadata-keys","errorCode":null,"errorMessage":"Error listing metadata keys.","messagePattern":"Error listing metadata keys\\.","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"src/backend/base/langflow/api/v1/knowledge_bases.py","lineNumber":1786,"sourceCode":"                            continue\n                        bucket = distinct.setdefault(key, {})\n                        # Array-valued metadata expands into one distinct value\n                        # per array entry so the popover dropdown shows every\n                        # tag that could be filtered on.\n                        candidates = value if isinstance(value, list) else [value]\n                        for candidate in candidates:\n                            if candidate is None:\n                                continue\n                            stringified = str(candidate)\n                            if stringified in bucket:\n                                continue\n                            if len(bucket) >= KB_METADATA_KEYS_VALUES_CAP:\n                                truncated = True\n                                break\n                            bucket[stringified] = None\n        except Exception as iter_error:\n            await logger.aerror(\"iter_documents failed while listing metadata keys for '%s': %s\", kb_name, iter_error)\n            raise HTTPException(status_code=500, detail=\"Error listing metadata keys.\") from iter_error\n\n        return KbMetadataKeysResponse(\n            keys={key: list(values.keys()) for key, values in sorted(distinct.items())},\n            truncated=truncated,\n        )\n\n    except HTTPException:\n        raise\n    except Exception as e:\n        await logger.aerror(\"Error listing metadata keys for '%s': %s\", kb_name, e)\n        raise HTTPException(status_code=500, detail=\"Error listing metadata keys.\") from e\n    finally:\n        if backend is not None:\n            try:\n                await backend.teardown()\n            except Exception as teardown_exc:  # noqa: BLE001\n                await logger.adebug(\"Backend teardown failed: %s\", teardown_exc)\n        if kb_path is not None and backend_type_value == BackendType.CHROMA.value:","sourceCodeStart":1768,"sourceCodeEnd":1804,"githubUrl":"https://github.com/langflow-ai/langflow/blob/976ec789d2886a86de109c044d089d68e96c9a35/src/backend/base/langflow/api/v1/knowledge_bases.py#L1768-L1804","documentation":"A 500 from the metadata-keys listing endpoint when iter_documents() raises while scanning the KB to collect distinct metadata keys and values. Mirrors the chunks endpoint: iteration errors over the vector store are logged ('iter_documents failed while listing metadata keys') and converted to this generic detail. Value buckets are capped at KB_METADATA_KEYS_VALUES_CAP with a truncated flag, but that is a normal result, not this error.","triggerScenarios":"GET /api/v1/knowledge_bases/{kb_name}/metadata/keys (metadata key listing) while the vector-store backend raises during document iteration — corrupted collection, concurrent lock, or remote store unreachable.","commonSituations":"Same class of failure as chunk iteration: corrupted Chroma data, concurrent writers, or network/credential issues with remote backends.","solutions":["Check server logs for the underlying iter_documents exception.","Resolve vector-store connectivity or lock contention.","Verify the KB's chunks endpoint also works (GET /{kb_name}/chunks) to confirm it is the store, not the metadata path.","Recreate/re-ingest the KB if the collection is corrupted."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    keys = await client.get(f\"/api/v1/knowledge_bases/{kb}/metadata/keys\").json()\nexcept HTTPStatusError as e:\n    if e.response.status_code == 500:\n        check_server_log(f\"iter_documents failed while listing metadata keys for '{kb}'\")\n        await degrade_gracefully()  # hide metadata filter UI until store recovers","preventionTips":["Treat metadata-keys 500s as vector-store health failures and back off.","Do not run heavy concurrent scans against the same Chroma directory.","Cache metadata keys client-side to reduce repeated full-collection iteration."],"tags":["knowledge-base","metadata","vector-store","http-500"],"backgroundTag":null,"analyzedSha":"976ec789d2886a86de109c044d089d68e96c9a35","analyzedAt":"2026-08-14T18:23:12.227Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}