zylon-ai/private-gpt · error · ValueError

mistral-common only supports function tools.

Error message

mistral-common only supports function tools.

What it means

When converting tools for mistral-common, the formatter only accepts tools whose type is 'function'; it strips unsupported keys inside tool['function'] with a warning, but any other tool type (e.g. custom providers' types) raises ValueError('mistral-common only supports function tools.').

Source

Thrown at private_gpt/components/llm/tokenizers/mistral.py:293

                    logger.warning(
                        "'%s' is not supported by mistral-common for tools. "
                        "It has been removed from the tool definition.",
                        tool_key,
                    )

                if tool["type"] == "function":
                    function_keys = list(tool["function"].keys())
                    for function_key in function_keys:
                        if function_key not in function_fields:
                            tool["function"].pop(function_key)
                            logger.warning(
                                "'%s' is not supported by mistral-common "
                                "for function tools. It has been removed from the "
                                "function definition.",
                                function_key,
                            )
                else:
                    raise ValueError("mistral-common only supports function tools.")

    return messages, tools


def _tekken_token_to_id(tokenizer: Any, token: str | bytes) -> int:
    """Convert a Tekken token to its ID, with fallback to UNK."""
    Tekkenizer = _load_mistral_module(
        "mistral_common.tokens.tokenizers.tekken"
    ).Tekkenizer

    assert isinstance(tokenizer, Tekkenizer), type(tokenizer)

    token_bytes = token.encode("utf-8") if not isinstance(token, bytes) else token
    shift = tokenizer.num_special_tokens

    try:
        return cast(int, shift + tokenizer._tekken_token2id_nospecial[token_bytes])
    except KeyError:

View on GitHub (pinned to 4a030776a3)

Solutions

  1. Filter the tools list to {'type': 'function'} entries before calling apply_chat_template.
  2. Rewrite non-function tool entries into function-tool form (name/description/parameters) if the capability can be expressed that way.
  3. Reject unsupported tool types at the API boundary with a clear error instead of letting them reach the tokenizer.

Example fix

# before
out = tok.apply_chat_template(msgs, tools=all_tools)  # includes {'type':'retrieval'}

# after
fn_tools = [t for t in all_tools if t.get('type') == 'function']
out = tok.apply_chat_template(msgs, tools=fn_tools)
Defensive patterns

Strategy: validation

Validate before calling

def sanitize_tools(tools: list[dict] | None) -> list[dict]:
    return [t for t in (tools or []) if t.get('type') == 'function']

out = tok.apply_chat_template(msgs, tools=sanitize_tools(tools))

Type guard

def is_function_tool(t: dict) -> bool:
    return t.get('type') == 'function' and isinstance(t.get('function'), dict)

Try / catch

try:
    out = tok.apply_chat_template(msgs, tools=tools)
except ValueError as e:
    if 'only supports function tools' in str(e):
        raise UnsupportedToolType('convert or drop non-function tools for mistral') from e
    raise

Prevention

When it happens

Trigger: Calling the mistral tokenizer's apply_chat_template with a tools list containing an entry like {'type': 'code_interpreter', ...} or any type != 'function'; typically from generic tool payloads forwarded verbatim from an OpenAI-compatible client.

Common situations: Upstream frameworks adding non-function tool types; clients sending tool definitions with extra metadata encoded in 'type'; migrations from OpenAI tool schemas that include hosted tool types.

Related errors


AI-assisted analysis of zylon-ai/private-gpt@4a030776a3 (2026-08-15). Data as JSON: /api/errors/511604e130d0fe97. Report an issue: GitHub.