{"record":{"id":"5f5b93f204ee046b","repo":"deepset-ai/haystack","slug":"the-pipeline-parameter-must-be-an-instance-of-pi","errorCode":null,"errorMessage":"The 'pipeline' parameter must be an instance of Pipeline. Got {type(pipeline)} instead.","messagePattern":"The 'pipeline' parameter must be an instance of Pipeline\\. Got (.+?) instead\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"haystack/tools/pipeline_tool.py","lineNumber":186,"sourceCode":"            Optional dictionary defining how tool outputs map to keys within state as well as optional handlers.\n            If the source is provided only the specified output key is sent to the handler.\n            Example:\n            ```python\n            {\n                \"documents\": {\"source\": \"docs\", \"handler\": custom_handler}\n            }\n            ```\n            If the source is omitted the whole tool result is sent to the handler.\n            Example:\n            ```python\n            {\n                \"documents\": {\"handler\": custom_handler}\n            }\n            ```\n        :raises ValueError: If the provided pipeline is not a valid Haystack Pipeline instance.\n        \"\"\"\n        if not isinstance(pipeline, Pipeline):\n            raise TypeError(f\"The 'pipeline' parameter must be an instance of Pipeline. Got {type(pipeline)} instead.\")\n\n        super().__init__(\n            component=SuperComponent(pipeline=pipeline, input_mapping=input_mapping, output_mapping=output_mapping),\n            name=name,\n            description=description,\n            parameters=parameters,\n            outputs_to_string=outputs_to_string,\n            inputs_from_state=inputs_from_state,\n            outputs_to_state=outputs_to_state,\n        )\n        self._unresolved_parameters = parameters\n        self._pipeline = pipeline\n        self._input_mapping = input_mapping\n        self._output_mapping = output_mapping\n\n    def to_dict(self) -> dict[str, Any]:\n        \"\"\"\n        Serializes the PipelineTool to a dictionary.","sourceCodeStart":168,"sourceCodeEnd":204,"githubUrl":"https://github.com/deepset-ai/haystack/blob/e318778c9bf60a1963e3b5f451359655dd696c30/haystack/tools/pipeline_tool.py#L168-L204","documentation":"PipelineTool.__init__ validates that the 'pipeline' argument is an actual haystack Pipeline instance before wrapping it in a SuperComponent. Passing anything else (a dict of pipeline data, None, a serialized pipeline, or another object) raises TypeError immediately.","triggerScenarios":"PipelineTool(pipeline=<not-a-Pipeline>) — e.g. passing the result of Pipeline.dumps()/to_dict(), a YAML string, None, or a component instead of a Pipeline.","commonSituations":"Loading pipelines from YAML/JSON and forgetting to call Pipeline.loads()/from_dict(); variable shadowing where 'pipeline' holds config data; passing a PipelineTool or component where a Pipeline is expected.","solutions":["Pass an instantiated Pipeline: PipelineTool(pipeline=Pipeline.loads(yaml_str))","If you have a dict, reconstruct with Pipeline.from_dict(data) before passing","Add isinstance(pipeline, Pipeline) check at call site before constructing PipelineTool"],"exampleFix":"// before\npipeline_tool = PipelineTool(pipeline=pipeline_dict)\n\n// after\nfrom haystack import Pipeline\npipeline_tool = PipelineTool(pipeline=Pipeline.from_dict(pipeline_dict))","handlingStrategy":"type-guard","validationCode":"from haystack import Pipeline\n\ndef build_pipeline_tool(pipeline, **kwargs):\n    if not isinstance(pipeline, Pipeline):\n        raise TypeError(f\"Expected Pipeline, got {type(pipeline).__name__}; use Pipeline.from_dict/loads\")\n    return PipelineTool(pipeline=pipeline, **kwargs)","typeGuard":"def is_pipeline(obj) -> bool:\n    from haystack import Pipeline\n    return isinstance(obj, Pipeline)","tryCatchPattern":"try:\n    pt = PipelineTool(pipeline=pipeline)\nexcept TypeError as e:\n    logger.error(\"pipeline arg invalid: %s\", e)\n    pipeline = Pipeline.loads(pipeline_yaml)\n    pt = PipelineTool(pipeline=pipeline)","preventionTips":["Never pass serialized pipeline dicts/YAML directly — reconstruct with Pipeline.from_dict / Pipeline.loads first","Add an isinstance(pipeline, Pipeline) assertion at the boundary where pipelines are loaded","Keep variable names distinct for pipeline config data vs the Pipeline instance"],"tags":["type-check","pipeline","tool-definition"],"backgroundTag":"wrong-argument-type","analyzedSha":"e318778c9bf60a1963e3b5f451359655dd696c30","analyzedAt":"2026-08-30T11:45:20.711Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}