{"record":{"id":"7d617092ebd0e40b","repo":"deepset-ai/haystack","slug":"a-component-named-name-already-exists-in-this","errorCode":null,"errorMessage":"A component named '{name}' already exists in this pipeline: choose another name.","messagePattern":"A component named '(.+?)' already exists in this pipeline: choose another name\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"haystack/core/pipeline/base.py","lineNumber":478,"sourceCode":"                    f\"Component instance cannot be added to the pipeline more than once. \"\n                    f\"It is mapped to both '{previous_name}' and '{name}'.\"\n                )\n\n            component_names_by_id[instance_id] = name\n            components_to_add.append((name, instance))\n\n        for name, instance in components_to_add:\n            self._add_component_to_graph(name, instance)\n\n        return self\n\n    def _validate_component(self, name: str, instance: Component) -> bool:\n        \"\"\"Validate a component before adding it, returning whether it needs to be added.\"\"\"\n        # Component names are unique\n        if name in self.graph.nodes:\n            if self.graph.nodes[name][\"instance\"] is instance:\n                return False\n            raise ValueError(f\"A component named '{name}' already exists in this pipeline: choose another name.\")\n\n        # Components can't be named `_debug`\n        if name == \"_debug\":\n            raise ValueError(\"'_debug' is a reserved name for debug output. Choose another name.\")\n\n        # Component names can't have \".\"\n        if \".\" in name:\n            raise ValueError(f\"{name} is an invalid component name, cannot contain '.' (dot) characters.\")\n\n        # Component instances must be components\n        if not isinstance(instance, Component):\n            raise PipelineValidationError(\n                f\"'{type(instance)}' doesn't seem to be a component. Is this class decorated with @component?\"\n            )\n\n        if owning_pipeline := getattr(instance, \"__haystack_added_to_pipeline__\", None):\n            if owning_pipeline is self:\n                existing_name = self.get_component_name(instance)","sourceCodeStart":460,"sourceCodeEnd":496,"githubUrl":"https://github.com/deepset-ai/haystack/blob/e318778c9bf60a1963e3b5f451359655dd696c30/haystack/core/pipeline/base.py#L460-L496","documentation":"Pipeline component names are unique node identifiers in the underlying graph. add_component() raises ValueError when the requested name already exists and the provided instance is not the exact instance already registered under that name (re-adding the same instance is silently a no-op, handled by _validate_component returning False).","triggerScenarios":"pipe.add_component(\"retriever\", r1) after \"retriever\" already holds a different instance; re-running notebook cells that re-add components under the same names; loops that add components with fixed names.","commonSituations":"Jupyter notebooks executed multiple times; templated pipeline builders where names collide; migration scripts re-registering components.","solutions":["Choose a unique name for the new component","Remove the existing component first with pipe.remove_component(name) then re-add","If the instance is identical, skip the call — adding the same instance under the same name is a no-op","In notebooks, restart the kernel or recreate the Pipeline object"],"exampleFix":"// before\npipe.add_component(\"ranker\", Ranker(top_k=5))  # 'ranker' exists\n// after\npipe.remove_component(\"ranker\")\npipe.add_component(\"ranker\", Ranker(top_k=5))","handlingStrategy":"validation","validationCode":"def can_add(pipe, name: str, instance) -> bool:\n    if name in pipe.graph.nodes:\n        return pipe.graph.nodes[name][\"instance\"] is instance\n    return True","typeGuard":"def is_new_or_same(pipe, name: str, instance) -> bool:\n    return name not in pipe.graph.nodes or pipe.graph.nodes[name][\"instance\"] is instance","tryCatchPattern":"try:\n    pipe.add_component(name, comp)\nexcept ValueError as e:\n    if \"already exists\" in str(e):\n        pipe.remove_component(name)\n        pipe.add_component(name, comp)\n    else:\n        raise","preventionTips":["Generate unique, parameterized names in loops (f\"{kind}_{i}\")","In notebooks, recreate the Pipeline instead of re-running add_component cells","Check `name in pipe.graph.nodes` before adding"],"tags":["python","pipeline","naming-conflict"],"backgroundTag":"duplicate-identifier","analyzedSha":"e318778c9bf60a1963e3b5f451359655dd696c30","analyzedAt":"2026-08-30T11:45:20.711Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}