langchain-ai/langchain · error · OutputParserException

Unknown tool type: {res['type']!r}. Available tools: {availa

Error message

Unknown tool type: {res['type']!r}. Available tools: {available}

What it means

Raised by PydanticToolsParser.parse_result when the model calls a tool whose name (res['type']) is not in the parser's name_dict of provided Pydantic tool schemas. The message lists the requested name and all available tool names to make the mismatch obvious.

Source

Thrown at libs/core/langchain_core/output_parsers/openai_tools.py:365

        pydantic_objects = []
        for res in json_results:
            if not isinstance(res["args"], dict):
                if partial:
                    continue
                msg = (
                    f"Tool arguments must be specified as a dict, received: "
                    f"{res['args']}"
                )
                raise ValueError(msg)

            try:
                tool = name_dict[res["type"]]
            except KeyError as e:
                available = ", ".join(name_dict.keys()) or "<no_tools>"
                msg = (
                    f"Unknown tool type: {res['type']!r}. Available tools: {available}"
                )
                raise OutputParserException(msg) from e

            try:
                pydantic_objects.append(tool(**res["args"]))
            except (ValidationError, ValueError):
                if partial:
                    continue
                has_max_tokens_stop_reason = any(
                    generation.message.response_metadata.get("stop_reason")
                    == "max_tokens"
                    for generation in result
                    if isinstance(generation, ChatGeneration)
                )
                if has_max_tokens_stop_reason:
                    logger.exception(_MAX_TOKENS_ERROR)
                raise
        if self.first_tool_only:
            return pydantic_objects[0] if pydantic_objects else None
        return pydantic_objects

View on GitHub (pinned to e32fa9a52e)

Solutions

  1. Align the tools list passed to PydanticToolsParser with the tools bound to the model (same classes/names)
  2. Make tool names unambiguous and consistent (check Pydantic model titles vs field names) to reduce hallucination
  3. Catch OutputParserException, inspect the 'Available tools' list in the message, and retry with corrected registration

Example fix

# before
llm = llm.bind_tools([WebSearch])
parser = PydanticToolsParser(tools=[Search])  # name mismatch -> hallucinated lookups fail

# after
llm = llm.bind_tools([WebSearch])
parser = PydanticToolsParser(tools=[WebSearch])
Defensive patterns

Strategy: try-catch

Validate before calling

known = {t.__name__ for t in tools}
unknown = [r["type"] for r in json_results if r["type"] not in known]
if unknown:
    ...  # log/re-prompt before parsing

Try / catch

from langchain_core.exceptions import OutputParserException
try:
    objs = parser.parse_result(result)
except OutputParserException as e:
    if "Unknown tool type" in str(e):
        objs = parser.parse_result(result, partial=True) or []  # skip unknown, keep known

Prevention

When it happens

Trigger: Model hallucinates a tool name not in the provided schemas (e.g. 'search_web' when only 'web_search' exists); parser constructed with a tools list that is out of sync with what was bound to the model; typo between bind_tools names and PydanticToolsParser(tools=[...]).

Common situations: Renaming a tool in one place but not the other; models inventing plausible tool names; few-shot examples in prompts referencing tools that are not actually registered.

Related errors


AI-assisted analysis of langchain-ai/langchain@e32fa9a52e (2026-08-14). Data as JSON: /api/errors/78a7b1f69372f609. Report an issue: GitHub.