{"record":{"id":"3da840ad1902fe14","repo":"microsoft/autogen","slug":"the-response-should-contain-content-but-the-conten","errorCode":null,"errorMessage":"The response should contain content but the content is empty. FinishReason: {finishReason}, FinishMessage: {finishMessage}","messagePattern":"The response should contain content but the content is empty\\. FinishReason: (.+?), FinishMessage: (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"dotnet/src/AutoGen.Gemini/Middleware/GeminiMessageConnector.cs","lineNumber":265,"sourceCode":"\n            return toolCallContents.Concat(toolCallResultContents);\n        }\n    }\n\n    private void ValidateGenerateContentResponse(GenerateContentResponse response)\n    {\n        if (response.Candidates.Count != 1)\n        {\n            throw new InvalidOperationException(\"The response should contain exactly one candidate.\");\n        }\n\n        var candidate = response.Candidates[0];\n        if (candidate.Content is null)\n        {\n            var finishReason = candidate.FinishReason;\n            var finishMessage = candidate.FinishMessage;\n\n            throw new InvalidOperationException($\"The response should contain content but the content is empty. FinishReason: {finishReason}, FinishMessage: {finishMessage}\");\n        }\n    }\n\n    private IEnumerable<IMessage> ProcessToolCallResultMessage(ToolCallResultMessage toolCallResultMessage, IAgent _)\n    {\n        var functionCallResultParts = new List<Part>();\n        foreach (var toolCallResult in toolCallResultMessage.ToolCalls)\n        {\n            if (toolCallResult.Result is null)\n            {\n                continue;\n            }\n\n            // if result is already a json object, use it as is\n            var json = toolCallResult.Result;\n            try\n            {\n                JsonNode.Parse(json);","sourceCodeStart":247,"sourceCodeEnd":283,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/dotnet/src/AutoGen.Gemini/Middleware/GeminiMessageConnector.cs#L247-L283","documentation":"GeminiMessageConnector.ValidateGenerateContentResponse throws this when the single candidate exists but its Content property is null, meaning the model finished without producing any content. The FinishReason and FinishMessage of the candidate are embedded in the message so the caller can see why generation stopped.","triggerScenarios":"Gemini finishes with STOP/SAFETY/MAX_TOKENS/RECITATION but attaches no Content object — e.g. output blocked by safety filters, token limit reached before any token was emitted, or an empty candidate echo.","commonSituations":"Prompts that trip safety filters; very low maxOutputTokens; model bugs or preview-model quirks returning contentless candidates; API contract changes between Google.Cloud.AIPlatform.Versions.","solutions":["Read FinishReason/FinishMessage from the exception text: SAFETY -> relax SafetySettings or rewrite the prompt; MAX_TOKENS -> raise maxOutputTokens; RECITATION -> rephrase.","Set explicit SafetySettings with lower block thresholds on the GenerateContentConfig if content was safety-blocked.","Retry once — transient empty candidates occur occasionally — then propagate the error.","Upgrade the AutoGen.Gemini / Google.Cloud.AIPlatform packages if the empty-content behavior comes from an SDK regression."],"exampleFix":"// before\nvar config = new GenerateContentConfig { MaxOutputTokens = 5 };\n\n// after\nvar config = new GenerateContentConfig\n{\n    MaxOutputTokens = 1024,\n    SafetySettings = { HarmCategory.HarmCategoryDangerousContent, HarmBlockThreshold.BlockOnlyHigh },\n};","handlingStrategy":"try-catch","validationCode":"var c = response.Candidates.FirstOrDefault();\nif (c?.Content is null)\n{\n    Console.WriteLine($\"Empty content, finish: {c?.FinishReason} {c?.FinishMessage}\");\n    // adjust prompt/config before mapping\n}","typeGuard":null,"tryCatchPattern":"try { var reply = await geminiAgent.SendAsync(msg); } catch (InvalidOperationException ex) when (ex.Message.Contains(\"content is empty\")) { /* raise MaxOutputTokens or rephrase prompt, retry once */ }","preventionTips":["Set generous MaxOutputTokens","Avoid prompts likely to trip safety/recitation filters","Surface FinishReason in your logs"],"tags":["gemini","empty-content","finish-reason","safety-filter"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}