{"record":{"id":"34bd6f165bb23895","repo":"microsoft/semantic-kernel","slug":"unexpected-response-from-model-34bd6f","errorCode":null,"errorMessage":"Unexpected response from model","messagePattern":"Unexpected response from model","errorType":"exception","errorClass":"KernelException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Connectors/Connectors.MistralAI/Client/MistralClient.cs","lineNumber":879,"sourceCode":"            if (string.Equals(tools[i].Function.Name, func.Name, StringComparison.OrdinalIgnoreCase))\n            {\n                return true;\n            }\n        }\n\n        return false;\n    }\n\n    private static T DeserializeResponse<T>(string body)\n    {\n        try\n        {\n            T? deserializedResponse = JsonSerializer.Deserialize<T>(body);\n            return deserializedResponse ?? throw new JsonException(\"Response is null\");\n        }\n        catch (JsonException exc)\n        {\n            throw new KernelException(\"Unexpected response from model\", exc)\n            {\n                Data = { { \"ResponseData\", body } },\n            };\n        }\n    }\n\n    private List<ChatMessageContent> ToChatMessageContent(string modelId, ChatCompletionResponse response)\n    {\n        return response.Choices!.Select(chatChoice => this.ToChatMessageContent(modelId, response, chatChoice)).ToList();\n    }\n\n    private ChatMessageContent ToChatMessageContent(string modelId, ChatCompletionResponse response, MistralChatChoice chatChoice)\n    {\n        var message = new ChatMessageContent(new AuthorRole(chatChoice.Message!.Role!), chatChoice.Message!.Content?.ToString(), modelId, chatChoice, Encoding.UTF8, GetChatChoiceMetadata(response, chatChoice));\n\n        if (chatChoice.IsToolCall)\n        {\n            foreach (var toolCall in chatChoice.ToolCalls!)","sourceCodeStart":861,"sourceCodeEnd":897,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/src/Connectors/Connectors.MistralAI/Client/MistralClient.cs#L861-L897","documentation":"Thrown as a KernelException with inner JsonException when the response body from the Mistral API cannot be deserialized into the expected ChatCompletionResponse type, or deserializes to null. The original response body is preserved in the exception's Data dictionary under 'ResponseData' for diagnostics. This typically indicates an API contract mismatch or an error response body.","triggerScenarios":"The Mistral endpoint returns an unexpected JSON shape (error page, rate-limit HTML, a new API version with a changed schema); the HTTP layer returned a 200 with a body that does not match ChatCompletionResponse; network proxy injecting unexpected content.","commonSituations":"Mistral API version changed and the connector is outdated; a corporate proxy returns an auth challenge page; the model endpoint is misconfigured (wrong base URL pointing to a non-Mistral service); rate limiting returning a non-JSON error.","solutions":["Inspect exception.Data['ResponseData'] to see the actual response body returned.","Verify the endpoint URI and API key are correct and point to the real Mistral API.","Update the Semantic Kernel Connectors.MistralAI package to the latest version to match the current API schema.","If behind a proxy, ensure it does not alter the response body or return HTML error pages."],"exampleFix":"try\n{\n    var result = await service.GetChatMessageContentAsync(history);\n}\ncatch (KernelException ex) when (ex.Data.Contains(\"ResponseData\"))\n{\n    var body = ex.Data[\"ResponseData\"] as string;\n    logger.LogError(\"Mistral returned unparseable response: {Body}\", body);\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try\n{\n    var result = await service.GetChatMessageContentAsync(history);\n}\ncatch (KernelException ex) when (ex.InnerException is JsonException)\n{\n    var body = ex.Data.Contains(\"ResponseData\") ? ex.Data[\"ResponseData\"]?.ToString() : null;\n    logger.LogError(ex, \"Failed to parse Mistral response. Body: {Body}\", body);\n}","preventionTips":["Keep the Connectors.MistralAI package updated to match the current API version.","Verify the endpoint URI points to the real Mistral API.","Log exception.Data['ResponseData'] to diagnose the actual response body.","Test API connectivity with a minimal request before production traffic."],"tags":["mistralai","deserialization","api-contract","kernel-exception"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}