microsoft/semantic-kernel · error · KernelException
Chat completions not found
Error message
Chat completions not found
What it means
Thrown by MistralClient.GetChatMessageContentsAsync when the non-streaming chat completion response is null, has a null Choices collection, or has zero choices. The connector cannot produce ChatMessageContent without at least one choice. It is a KernelException raised after the HTTP call succeeded but the payload was empty.
Source
Thrown at dotnet/src/Connectors/Connectors.MistralAI/Client/MistralClient.cs:73
var endpoint = this.GetEndpoint(mistralExecutionSettings, path: "chat/completions");
var autoInvoke = kernel is not null && mistralExecutionSettings.ToolCallBehavior?.MaximumAutoInvokeAttempts > 0 && s_inflightAutoInvokes.Value < MaxInflightAutoInvokes;
for (int requestIndex = 1; ; requestIndex++)
{
var chatRequest = this.CreateChatCompletionRequest(modelId, stream: false, chatHistory, mistralExecutionSettings, kernel);
ChatCompletionResponse? responseData = null;
List<ChatMessageContent> responseContent;
using (var activity = ModelDiagnostics.StartCompletionActivity(this._endpoint, this._modelId, ModelProvider, chatHistory, mistralExecutionSettings))
{
try
{
using var httpRequestMessage = this.CreatePost(chatRequest, endpoint, this._apiKey, stream: false);
responseData = await this.SendRequestAsync<ChatCompletionResponse>(httpRequestMessage, cancellationToken).ConfigureAwait(false);
this.LogUsage(responseData?.Usage);
if (responseData is null || responseData.Choices is null || responseData.Choices.Count == 0)
{
throw new KernelException("Chat completions not found");
}
}
catch (Exception ex) when (activity is not null)
{
activity.SetError(ex);
// Capture available metadata even if the operation failed.
if (responseData is not null)
{
if (responseData.Id is string id)
{
activity.SetResponseId(id);
}
if (responseData.Usage is MistralUsage usage)
{
if (usage.PromptTokens is int promptTokens)
{View on GitHub (pinned to c028a0c7dc)
Solutions
- Inspect the raw response and any moderation/safety fields (enable logging) to see why no choice was returned.
- Retry once for transient API faults.
- Adjust the prompt or moderation settings if content was filtered.
- Verify the model id is valid and your plan has access to it.
Example fix
// before
var result = await kernel.InvokePromptAsync(prompt, new(new MistralAIPromptExecutionSettings())); // throws
// after (handle empty-completion gracefully)
try
{
var result = await kernel.InvokePromptAsync(prompt, new(new MistralAIPromptExecutionSettings()));
}
catch (KernelException ex) when (ex.Message == "Chat completions not found")
{
logger.LogWarning("Mistral returned no chat completions; prompt may be filtered.");
// fallback or re-prompt
} Defensive patterns
Strategy: try-catch
Try / catch
try
{
var result = await kernel.InvokePromptAsync(prompt, new(new MistralAIPromptExecutionSettings()));
}
catch (KernelException ex) when (ex.Message == "Chat completions not found")
{
logger.LogWarning("Mistral returned no chat completions; prompt may be filtered or model unavailable.");
// fallback, re-prompt, or surface to user
} Prevention
- Enable response logging to inspect safety/moderation fields.
- Retry once for transient API faults.
- Adjust prompts that may trip content filters.
- Confirm the model id and your plan's access.
When it happens
Trigger: The Mistral API returned a 2xx response with no choices (e.g. content filtered entirely, all candidates blocked, an empty completion, or an unexpected API-side issue).
Common situations: Safety/content filters rejecting the entire generation; misconfigured model id; API quota/availability returning a degenerate 200; transient API faults; prompt that triggers a moderation block.
Related errors
- Role must be one of: system, user, assistant or tool. {role}
- Run failed with status: `{response.Status}` for agent `{agen
- Unsupported Mistral model: {modelId}
- Prompt was blocked due to Gemini API safety reasons.
- Unexpected response from model
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/650654661d4286c5.
Report an issue: GitHub.