-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Description
Describe the bug
When using Semantic Kernel with a model served by Mistral via LiteLLM, requests fail with the following error:
litellm.BadRequestError: MistralException - Error code: 422 - {
'detail': [
{
'type': 'missing',
'loc': ['body', 'tools', 'list[Tool]', 0, 'function', 'parameters'],
'msg': 'Field required',
'input': {'name': 'NonInvocableTool'}
}
]
}
This occurs because Semantic Kernel includes a placeholder tool named NonInvocableTool to temporarily disable function calling. This tool lacks a parameters field, which is accepted by most models (e.g., OpenAI), but rejected by Mistral due to stricter schema validation.
To Reproduce
Steps to reproduce the behavior:
-
Use Semantic Kernel to call a Mistral model through LiteLLM with required function calling.
-
Ensure that function calling is disabled or no tools are invocable, triggering the addition of NonInvocableTool.
-
Make a chat completion request.
-
See error from LiteLLM/Mistral rejecting the request due to invalid tool schema.
Expected behavior
The placeholder 'NonInvocableTool' should adhere to the proper tool json schema, such that providers with stricter schema validation can also accept requests.
Screenshots
N/A — error is textual and occurs in request pipeline.
Platform
- Language: C#
- Source: main branch
- AI model: mistral-medium
- IDE: Visual Studio
- OS: Windows
Additional context
The issue was worked around by creating a proxy implementation of OpenAIClient and ChatClient, stripping NonInvocableTool from the tool list when targeting Mistral models:
class OpenAIClientProxy(OpenAIClient implementation) : OpenAIClient
{
class ChatClientProxy(ChatClient implementation, string model) : ChatClient
{
public override AsyncCollectionResult<StreamingChatCompletionUpdate> CompleteChatStreamingAsync(IEnumerable<OpenAI.Chat.ChatMessage> messages, ChatCompletionOptions options = null, CancellationToken cancellationToken = default)
{
if (model.StartsWith("mistral-", StringComparison.OrdinalIgnoreCase))
{
var nonInvocableTool = options?.Tools.FirstOrDefault(t => t.FunctionName == "NonInvocableTool");
if (nonInvocableTool != null)
options?.Tools.Remove(nonInvocableTool);
}
return implementation.CompleteChatStreamingAsync(messages, options, cancellationToken);
}
}
public override ChatClient GetChatClient(string model) => new ChatClientProxy(implementation.GetChatClient(model), model);
}
This avoids the 422 error by omitting the placeholder tool before the request is sent.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status