{"record":{"id":"e8b8326e9c78cd87","repo":"microsoft/semantic-kernel","slug":"failed-to-get-a-response-from-the-chat-completion","errorCode":null,"errorMessage":"Failed to get a response from the chat completion service.","messagePattern":"Failed to get a response from the chat completion service\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"dotnet/samples/GettingStartedWithProcesses/Step01/Step01_Processes.cs","lineNumber":170,"sourceCode":"            return ValueTask.CompletedTask;\n        }\n\n        /// <summary>\n        /// Generates a response from the chat completion service.\n        /// </summary>\n        /// <param name=\"context\">The context for the current step and process. <see cref=\"KernelProcessStepContext\"/></param>\n        /// <param name=\"userMessage\">The user message from a previous step.</param>\n        /// <param name=\"_kernel\">A <see cref=\"Kernel\"/> instance.</param>\n        /// <returns></returns>\n        [KernelFunction(ProcessFunctions.GetChatResponse)]\n        public async Task GetChatResponseAsync(KernelProcessStepContext context, string userMessage, Kernel _kernel)\n        {\n            _state!.ChatMessages.Add(new(AuthorRole.User, userMessage));\n            IChatCompletionService chatService = _kernel.Services.GetRequiredService<IChatCompletionService>();\n            ChatMessageContent response = await chatService.GetChatMessageContentAsync(_state.ChatMessages).ConfigureAwait(false);\n            if (response == null)\n            {\n                throw new InvalidOperationException(\"Failed to get a response from the chat completion service.\");\n            }\n\n            System.Console.ForegroundColor = ConsoleColor.Yellow;\n            System.Console.WriteLine($\"ASSISTANT: {response.Content}\");\n            System.Console.ResetColor();\n\n            // Update state with the response\n            _state.ChatMessages.Add(response);\n\n            // emit event: assistantResponse\n            await context.EmitEventAsync(new KernelProcessEvent { Id = ChatBotEvents.AssistantResponseGenerated, Data = response });\n        }\n    }\n\n    /// <summary>\n    /// The state object for the <see cref=\"ChatBotResponseStep\"/>.\n    /// </summary>\n    private sealed class ChatBotState","sourceCodeStart":152,"sourceCodeEnd":188,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/samples/GettingStartedWithProcesses/Step01/Step01_Processes.cs#L152-L188","documentation":"Thrown by the chatbot process step when IChatCompletionService.GetChatMessageContentAsync returns a null ChatMessageContent. The Semantic Kernel chat completion contract normally returns a non-null message, so a null result indicates the underlying service failed to produce any content (model error, empty deployment, transport failure swallowed).","triggerScenarios":"Invoking the GetChatResponseAsync kernel function in Step01_Processes when the registered IChatCompletionService returns null; e.g. misconfigured model/deployment id, empty chat history, or a backend that returned an empty body.","commonSituations":"Wrong deployment/model id for Azure OpenAI; chat history with no messages; connector version mismatch where the service returns null instead of throwing; rate-limited or empty completion response.","solutions":["Verify an IChatCompletionService is registered on the kernel and the deployment/model id is correct.","Inspect _state.ChatMessages passed in to confirm it is non-empty and well-formed.","Upgrade or align the Semantic Kernel connector packages so GetChatMessageContentAsync throws on failure rather than returning null.","Wrap the call to surface the underlying HTTP error instead of a generic message."],"exampleFix":"// before\nChatMessageContent response = await chatService.GetChatMessageContentAsync(_state.ChatMessages).ConfigureAwait(false);\nif (response == null) { throw new InvalidOperationException(\"Failed to get a response from the chat completion service.\"); }\n// after - also log the request shape and inner cause\nChatMessageContent? response;\ntry { response = await chatService.GetChatMessageContentAsync(_state.ChatMessages).ConfigureAwait(false); }\ncatch (Exception ex) { throw new InvalidOperationException(\"Chat completion call failed.\", ex); }\nif (response is null) throw new InvalidOperationException($\"No content returned for {_state.ChatMessages.Count} messages.\");","handlingStrategy":"try-catch","validationCode":"var chatService = kernel.Services.GetService<IChatCompletionService>();\nif (chatService is null) throw new InvalidOperationException(\"No IChatCompletionService registered.\");\nif (_state.ChatMessages.Count == 0) _state.ChatMessages.Add(new(AuthorRole.User, \"hello\"));","typeGuard":"bool HasChatCompletion(Kernel k) => k.Services.GetService<IChatCompletionService>() is not null;","tryCatchPattern":"ChatMessageContent response;\ntry { response = await chatService.GetChatMessageContentAsync(_state.ChatMessages); }\ncatch (HttpRequestException ex) { /* surface real HTTP error */ throw; }\nif (response is null) { /* log + fallback or retry */ }","preventionTips":["Always register an IChatCompletionService on the kernel before invoking completion steps.","Confirm the model/deployment id matches an existing deployment.","Never pass an empty chat history to a completion call."],"tags":["chat-completion","processes","openai","azure","configuration"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}