{"record":{"id":"46e70e5cd3e521ba","repo":"microsoft/autogen","slug":"invalid-chatresponsemessage-46e70e","errorCode":null,"errorMessage":"Invalid ChatResponseMessage","messagePattern":"Invalid ChatResponseMessage","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"dotnet/src/AutoGen.OpenAI.V1/Middleware/OpenAIChatRequestMessageConnector.cs","lineNumber":167,"sourceCode":"        {\n            var functionToolCalls = chatResponseMessage.ToolCalls\n                .Where(tc => tc is ChatCompletionsFunctionToolCall)\n                .Select(tc => (ChatCompletionsFunctionToolCall)tc);\n\n            var toolCalls = functionToolCalls.Select(tc => new ToolCall(tc.Name, tc.Arguments) { ToolCallId = tc.Id });\n\n            return new ToolCallMessage(toolCalls, from)\n            {\n                Content = textContent,\n            };\n        }\n\n        if (textContent is string content && !string.IsNullOrEmpty(content))\n        {\n            return new TextMessage(Role.Assistant, content, from);\n        }\n\n        throw new InvalidOperationException(\"Invalid ChatResponseMessage\");\n    }\n\n    public IEnumerable<IMessage> ProcessIncomingMessages(IAgent agent, IEnumerable<IMessage> messages)\n    {\n        return messages.SelectMany<IMessage, IMessage>(m =>\n        {\n            if (m is IMessage<ChatRequestMessage> crm)\n            {\n                return [crm];\n            }\n            else\n            {\n                var chatRequestMessages = m switch\n                {\n                    TextMessage textMessage => ProcessTextMessage(agent, textMessage),\n                    ImageMessage imageMessage when (imageMessage.From is null || imageMessage.From != agent.Name) => ProcessImageMessage(agent, imageMessage),\n                    MultiModalMessage multiModalMessage when (multiModalMessage.From is null || multiModalMessage.From != agent.Name) => ProcessMultiModalMessage(agent, multiModalMessage),\n                    ToolCallMessage toolCallMessage when (toolCallMessage.From is null || toolCallMessage.From == agent.Name) => ProcessToolCallMessage(agent, toolCallMessage),","sourceCodeStart":149,"sourceCodeEnd":185,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/dotnet/src/AutoGen.OpenAI.V1/Middleware/OpenAIChatRequestMessageConnector.cs#L149-L185","documentation":"Thrown by PostProcessChatResponseMessage when a ChatResponseMessage carries no function call, no tool calls, and null/empty text content. The connector has nothing to map into a TextMessage or ToolCallMessage, so it treats the response as malformed. Typical causes are content filtering (empty completion), reasoning models that return content in a different field, or SDK version drift where content moved.","triggerScenarios":"A ChatCompletions response whose Message has empty Content and no FunctionCall/ToolCalls — e.g. finish_reason content_filter with empty body, or an assistant reply that only contains tool-call outputs not exposed on this SDK version.","commonSituations":"Deployments where content filter removes the text; models that return empty content on truncation (max_tokens hit); mismatch between the Azure.OpenAI SDK version the connector was built against and the API's actual response shape.","solutions":["Inspect message.Content.Choices[0].FinishReason to see why content is empty (content_filter, length, etc.) and address that first","Increase TokenChoiceCount/max tokens if truncation produced an empty completion","Verify the Azure.OpenAI package version matches the one AutoGen.OpenAI.V1 was compiled against","Catch InvalidOperationException and retry or substitute a default assistant message"],"exampleFix":"// before\nvar reply = await agent.SendAsync(prompt); // throws 'Invalid ChatResponseMessage'\n\n// after\n// check finish reason on the raw completion before the connector maps it\nif (completion.Choices[0].FinishReason == CompletionsFinishReason.ContentFiltered)\n{\n    // handle filtered response explicitly\n}","handlingStrategy":"validation","validationCode":"var choice = completion.Choices[0];\nbool hasContent = !string.IsNullOrEmpty(choice.Message.Content)\n    || choice.Message.FunctionCall is not null\n    || choice.Message.ToolCalls.Count > 0;\nif (!hasContent) { /* inspect FinishReason before the connector throws */ }","typeGuard":null,"tryCatchPattern":"catch (InvalidOperationException ex) when (ex.Message == \"Invalid ChatResponseMessage\") { /* retry or log finish reason */ }","preventionTips":["Check FinishReason on raw completions in tests","Keep Azure.OpenAI SDK version aligned with the AutoGen package","Avoid max_tokens values that truncate completions to empty"],"tags":["autogen","dotnet","azure-openai","empty-response","message-connector"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}