{"record":{"id":"5907bfec44c43ad9","repo":"PrefectHQ/fastmcp","slug":"no-content-in-response-from-completion-finish-rea","errorCode":null,"errorMessage":"No content in response from completion (finish_reason={finish})","messagePattern":"No content in response from completion \\(finish_reason=(.+?)\\)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"fastmcp_slim/fastmcp/client/sampling/handlers/google_genai.py","lineNumber":400,"sourceCode":"            # Note: Skip thought parts from thinking_config - not relevant for MCP responses\n            if part.text and not part.thought:\n                content.append(TextContent(type=\"text\", text=part.text))\n            elif part.function_call is not None:\n                fc = part.function_call\n                fc_name: str = fc.name or \"unknown\"\n                content.append(\n                    ToolUseContent(\n                        type=\"tool_use\",\n                        id=f\"{fc_name}_{uuid4().hex[:8]}\",  # Generate unique ID\n                        name=fc_name,\n                        input=dict(fc.args) if fc.args else {},\n                    )\n                )\n\n    if not content:\n        finish = candidate.finish_reason if candidate else \"unknown\"\n        msg = f\"No content in response from completion (finish_reason={finish})\"\n        raise ValueError(msg)\n\n    return CreateMessageResultWithTools(\n        content=content,\n        role=\"assistant\",\n        model=model,\n        stop_reason=stop_reason,\n    )\n","sourceCodeStart":382,"sourceCodeEnd":408,"githubUrl":"https://github.com/PrefectHQ/fastmcp/blob/1f021142978e0861cd910c8df4e8074bc7cf3978/fastmcp_slim/fastmcp/client/sampling/handlers/google_genai.py#L382-L408","documentation":"On the tool-calling sampling path (_response_to_result_with_tools), the handler collected no usable content parts (thought parts are filtered out) from the candidate, so it cannot build a CreateMessageResultWithTools. The finish_reason is included to aid diagnosis.","triggerScenarios":"A Gemini response contains only thought/reasoning parts (filtered), or the candidate is empty/blocked, while processing a sampling request that included tools.","commonSituations":"Thinking models spending all output on reasoning; SAFETY/RECITATION finish reasons with no text; malformed tool declarations causing immediate stop; zero max_tokens.","solutions":["Check finish_reason in the error message and address the underlying cause (safety block, truncation).","Reduce or disable thinking output so the model emits final content.","Increase max_tokens for the sampling request.","Verify tool declarations are valid; adjust prompts if the model refuses to answer."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"null","typeGuard":"null","tryCatchPattern":"try:\n    result = await client.sample(messages=messages, tools=tools, ...)\nexcept ValueError as e:\n    if 'No content in response from completion' in str(e):\n        result = await retry_with_revised_request()\n    else:\n        raise","preventionTips":["Check finish_reason embedded in the error message and address its cause.","Avoid zero/truncating max_tokens on tool paths with thinking models.","Validate tool declarations are well-formed before sampling."],"tags":["sampling","google-genai","empty-response","tool-calls"],"backgroundTag":"empty-completion-response","analyzedSha":"1f021142978e0861cd910c8df4e8074bc7cf3978","analyzedAt":"2026-08-29T14:31:16.082Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}