run-llama/llama_index · error · NotImplementedError

`as_langchain_tool` not implemented here.

Error message

`as_langchain_tool` not implemented here.

What it means

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.

Source

Thrown at llama-index-core/llama_index/core/tools/retriever_tool.py:126

            )
        if query_str == "":
            raise ValueError("Cannot call query engine without inputs")
        docs = await self._retriever.aretrieve(query_str)
        content = ""
        docs = await self._async_apply_node_postprocessors(docs, QueryBundle(query_str))
        for doc in docs:
            assert isinstance(doc.node, (Node, TextNode))
            node_copy = doc.node.model_copy()
            content += node_copy.get_content(MetadataMode.LLM) + "\n\n"
        return ToolOutput(
            content=content,
            tool_name=self.metadata.get_name(),
            raw_input={"input": query_str},
            raw_output=docs,
        )

    def as_langchain_tool(self) -> "LlamaIndexTool":
        raise NotImplementedError("`as_langchain_tool` not implemented here.")

    def _apply_node_postprocessors(
        self, nodes: List[NodeWithScore], query_bundle: QueryBundle
    ) -> List[NodeWithScore]:
        for node_postprocessor in self._node_postprocessors:
            nodes = node_postprocessor.postprocess_nodes(
                nodes, query_bundle=query_bundle
            )
        return nodes

    async def _async_apply_node_postprocessors(
        self, nodes: List[NodeWithScore], query_bundle: QueryBundle
    ) -> List[NodeWithScore]:
        for node_postprocessor in self._node_postprocessors:
            nodes = await node_postprocessor.apostprocess_nodes(
                nodes, query_bundle=query_bundle
            )
        return nodes

View on GitHub (pinned to afd0fef371)

Solutions

  1. 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.
  2. 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.
  3. If you control the call site, skip or special-case RetrieverTool before calling as_langchain_tool() on mixed tool lists.

Example fix

// before
retriever_tool = RetrieverTool.from_defaults(retriever=retriever)
lc_tool = retriever_tool.as_langchain_tool()  # NotImplementedError

// after
from llama_index.langchain.tools import LlamaIndexTool
lc_tool = LlamaIndexTool.from_query_engine(query_engine)
Defensive patterns

Strategy: type-guard

Validate before calling

from llama_index.core.tools import RetrieverTool

def can_convert_to_langchain(tool) -> bool:
    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')

Type guard

from llama_index.core.tools import RetrieverTool

def is_retriever_tool(tool) -> bool:
    """True when as_langchain_tool() would raise NotImplementedError."""
    return isinstance(tool, RetrieverTool)

Try / catch

try:
    lc_tool = tool.as_langchain_tool()
except NotImplementedError:
    # route through the llama-index-langchain adapter instead
    lc_tool = LlamaIndexTool.from_query_engine(query_engine)

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of run-llama/llama_index@afd0fef371 (2026-08-15). Data as JSON: /api/errors/d5a69d65a4bd4ddc. Report an issue: GitHub.