{"record":{"id":"511604e130d0fe97","repo":"zylon-ai/private-gpt","slug":"mistral-common-only-supports-function-tools","errorCode":null,"errorMessage":"mistral-common only supports function tools.","messagePattern":"mistral-common only supports function tools\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"private_gpt/components/llm/tokenizers/mistral.py","lineNumber":293,"sourceCode":"                    logger.warning(\n                        \"'%s' is not supported by mistral-common for tools. \"\n                        \"It has been removed from the tool definition.\",\n                        tool_key,\n                    )\n\n                if tool[\"type\"] == \"function\":\n                    function_keys = list(tool[\"function\"].keys())\n                    for function_key in function_keys:\n                        if function_key not in function_fields:\n                            tool[\"function\"].pop(function_key)\n                            logger.warning(\n                                \"'%s' is not supported by mistral-common \"\n                                \"for function tools. It has been removed from the \"\n                                \"function definition.\",\n                                function_key,\n                            )\n                else:\n                    raise ValueError(\"mistral-common only supports function tools.\")\n\n    return messages, tools\n\n\ndef _tekken_token_to_id(tokenizer: Any, token: str | bytes) -> int:\n    \"\"\"Convert a Tekken token to its ID, with fallback to UNK.\"\"\"\n    Tekkenizer = _load_mistral_module(\n        \"mistral_common.tokens.tokenizers.tekken\"\n    ).Tekkenizer\n\n    assert isinstance(tokenizer, Tekkenizer), type(tokenizer)\n\n    token_bytes = token.encode(\"utf-8\") if not isinstance(token, bytes) else token\n    shift = tokenizer.num_special_tokens\n\n    try:\n        return cast(int, shift + tokenizer._tekken_token2id_nospecial[token_bytes])\n    except KeyError:","sourceCodeStart":275,"sourceCodeEnd":311,"githubUrl":"https://github.com/zylon-ai/private-gpt/blob/4a030776a31a901ad80b1bf4d7faa2c1a367efbb/private_gpt/components/llm/tokenizers/mistral.py#L275-L311","documentation":"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.').","triggerScenarios":"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.","commonSituations":"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.","solutions":["Filter the tools list to {'type': 'function'} entries before calling apply_chat_template.","Rewrite non-function tool entries into function-tool form (name/description/parameters) if the capability can be expressed that way.","Reject unsupported tool types at the API boundary with a clear error instead of letting them reach the tokenizer."],"exampleFix":"# before\nout = tok.apply_chat_template(msgs, tools=all_tools)  # includes {'type':'retrieval'}\n\n# after\nfn_tools = [t for t in all_tools if t.get('type') == 'function']\nout = tok.apply_chat_template(msgs, tools=fn_tools)","handlingStrategy":"validation","validationCode":"def sanitize_tools(tools: list[dict] | None) -> list[dict]:\n    return [t for t in (tools or []) if t.get('type') == 'function']\n\nout = tok.apply_chat_template(msgs, tools=sanitize_tools(tools))","typeGuard":"def is_function_tool(t: dict) -> bool:\n    return t.get('type') == 'function' and isinstance(t.get('function'), dict)","tryCatchPattern":"try:\n    out = tok.apply_chat_template(msgs, tools=tools)\nexcept ValueError as e:\n    if 'only supports function tools' in str(e):\n        raise UnsupportedToolType('convert or drop non-function tools for mistral') from e\n    raise","preventionTips":["Filter tool payloads to type=='function' at the client/adapter boundary.","Reject or translate non-function tool types with an explicit user-facing error.","Track upstream schema changes when upgrading frameworks that emit richer tool types."],"tags":["mistral","tools","function-calling","validation"],"backgroundTag":null,"analyzedSha":"4a030776a31a901ad80b1bf4d7faa2c1a367efbb","analyzedAt":"2026-08-15T03:51:26.951Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}