{"record":{"id":"d5a69d65a4bd4ddc","repo":"run-llama/llama_index","slug":"as-langchain-tool-not-implemented-here","errorCode":null,"errorMessage":"`as_langchain_tool` not implemented here.","messagePattern":"`as_langchain_tool` not implemented here\\.","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"llama-index-core/llama_index/core/tools/retriever_tool.py","lineNumber":126,"sourceCode":"            )\n        if query_str == \"\":\n            raise ValueError(\"Cannot call query engine without inputs\")\n        docs = await self._retriever.aretrieve(query_str)\n        content = \"\"\n        docs = await self._async_apply_node_postprocessors(docs, QueryBundle(query_str))\n        for doc in docs:\n            assert isinstance(doc.node, (Node, TextNode))\n            node_copy = doc.node.model_copy()\n            content += node_copy.get_content(MetadataMode.LLM) + \"\\n\\n\"\n        return ToolOutput(\n            content=content,\n            tool_name=self.metadata.get_name(),\n            raw_input={\"input\": query_str},\n            raw_output=docs,\n        )\n\n    def as_langchain_tool(self) -> \"LlamaIndexTool\":\n        raise NotImplementedError(\"`as_langchain_tool` not implemented here.\")\n\n    def _apply_node_postprocessors(\n        self, nodes: List[NodeWithScore], query_bundle: QueryBundle\n    ) -> List[NodeWithScore]:\n        for node_postprocessor in self._node_postprocessors:\n            nodes = node_postprocessor.postprocess_nodes(\n                nodes, query_bundle=query_bundle\n            )\n        return nodes\n\n    async def _async_apply_node_postprocessors(\n        self, nodes: List[NodeWithScore], query_bundle: QueryBundle\n    ) -> List[NodeWithScore]:\n        for node_postprocessor in self._node_postprocessors:\n            nodes = await node_postprocessor.apostprocess_nodes(\n                nodes, query_bundle=query_bundle\n            )\n        return nodes","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/run-llama/llama_index/blob/afd0fef371831f9bda13e5af7167cf4e981278ab/llama-index-core/llama_index/core/tools/retriever_tool.py#L108-L144","documentation":"RetrieverTool does not implement as_langchain_tool(); calling it always raises NotImplementedError. The method exists on the base Tool interface (or is expected by LangChain adapter code), but the retriever tool subclass deliberately leaves it unimplemented. It signals that this tool type cannot be wrapped directly as a LangChain tool via this method.","triggerScenarios":"Calling retriever_tool.as_langchain_tool() on any RetrieverTool instance (e.g. built via RetrieverTool.from_defaults). Generic code that iterates over a tool list and calls as_langchain_tool() on each item will hit this when the list contains a RetrieverTool.","commonSituations":"Migrating an agent from LangChain to LlamaIndex (or vice versa) and trying to convert existing LlamaIndex retriever tools into LangChain tools. Also hit when an agent framework wrapper assumes every tool supports LangChain conversion.","solutions":["Use the dedicated adapter in the llama-index-integrations/langchain package: from llama_index.langchain.tools import LlamaIndexTool (or from langchain.tools import load_tool) and pass a query engine/retriever instead of converting RetrieverTool.","Wrap the retriever in a QueryEngine (e.g. ret_query_engine = index.as_query_engine()) and expose that to LangChain, since query-engine-backed conversions are supported.","If you control the call site, skip or special-case RetrieverTool before calling as_langchain_tool() on mixed tool lists."],"exampleFix":"// before\nretriever_tool = RetrieverTool.from_defaults(retriever=retriever)\nlc_tool = retriever_tool.as_langchain_tool()  # NotImplementedError\n\n// after\nfrom llama_index.langchain.tools import LlamaIndexTool\nlc_tool = LlamaIndexTool.from_query_engine(query_engine)","handlingStrategy":"type-guard","validationCode":"from llama_index.core.tools import RetrieverTool\n\ndef can_convert_to_langchain(tool) -> bool:\n    return not isinstance(tool, RetrieverTool) and tool.as_langchain_tool.__func__ is not object.__getattribute__(type('X', (), {'as_langchain_tool': lambda self: None}), 'as_langchain_tool')","typeGuard":"from llama_index.core.tools import RetrieverTool\n\ndef is_retriever_tool(tool) -> bool:\n    \"\"\"True when as_langchain_tool() would raise NotImplementedError.\"\"\"\n    return isinstance(tool, RetrieverTool)","tryCatchPattern":"try:\n    lc_tool = tool.as_langchain_tool()\nexcept NotImplementedError:\n    # route through the llama-index-langchain adapter instead\n    lc_tool = LlamaIndexTool.from_query_engine(query_engine)","preventionTips":["Check isinstance(tool, RetrieverTool) before generic as_langchain_tool loops.","Prefer the llama-index-langchain adapter package for cross-framework conversion.","Keep a unit test that converts every registered tool so unsupported types fail in CI, not prod."],"tags":["langchain","retriever","tool-adapter","not-implemented"],"backgroundTag":null,"analyzedSha":"afd0fef371831f9bda13e5af7167cf4e981278ab","analyzedAt":"2026-08-15T05:42:58.429Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}