BerriAI/litellm · error · ValueError

Advisor tool must have a valid model

Error message

Advisor tool must have a valid model

What it means

Tool-mapping guard in the Anthropic chat transformation: the advisor tool's model field is missing or not a valid string, so the tool cannot be constructed with a routable model.

Solutions

  1. Set a valid 'model' field on the advisor tool definition.
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at litellm/llms/anthropic/chat/transformation.py:759 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18). Data as JSON: /api/errors/8127354fae33233a. Report an issue: GitHub.

Appendix: source

Thrown at litellm/llms/anthropic/chat/transformation.py:759

        elif tool["type"] == "tool_search_tool_bm25_20251119":
            # Tool search tool using BM25
            from litellm.types.llms.anthropic import AnthropicToolSearchToolBM25

            tool_name_obj = tool.get("name", "tool_search_tool_bm25")
            if not isinstance(tool_name_obj, str):
                raise ValueError("Tool search tool must have a valid name")
            tool_name = tool_name_obj
            returned_tool = AnthropicToolSearchToolBM25(
                type="tool_search_tool_bm25_20251119",
                name=tool_name,
            )
        elif tool["type"] == ANTHROPIC_ADVISOR_TOOL_TYPE:
            from litellm.types.llms.anthropic import AnthropicAdvisorTool

            _tool_dict: Final = cast(dict, tool)
            advisor_model: Final = _tool_dict.get("model")
            if not isinstance(advisor_model, str):
                raise ValueError("Advisor tool must have a valid model")
            _advisor_tool: Final = AnthropicAdvisorTool(
                type=ANTHROPIC_ADVISOR_TOOL_TYPE,
                name="advisor",
                model=advisor_model,
            )
            if _tool_dict.get("max_uses") is not None:
                _advisor_tool["max_uses"] = _tool_dict["max_uses"]
            if _tool_dict.get("caching") is not None:
                _advisor_tool["caching"] = _tool_dict["caching"]
            returned_tool = _advisor_tool
        if returned_tool is None and mcp_server is None:
            raise ValueError(f"Unsupported tool type: {tool['type']}")

        ## check if cache_control is set in the tool
        _cache_control: Final = tool.get("cache_control", None)
        _cache_control_function: Final = tool.get("function", {}).get("cache_control", None)
        if returned_tool is not None:
            # Only set cache_control on tools that support it (not tool search tools)

View on GitHub (pinned to 77b7c6c40c)