{"record":{"id":"6d4cdb1ff61a35a5","repo":"PrefectHQ/fastmcp","slug":"model-returned-only-thinking-reasoning-content-wit","errorCode":null,"errorMessage":"Model returned only thinking/reasoning content with no response text. / No content in response (finish_reason={candidate.finish_reason})","messagePattern":"Model returned only thinking/reasoning content with no response text\\. / No content in response \\(finish_reason=(.+?)\\)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"fastmcp_slim/fastmcp/client/sampling/handlers/google_genai.py","lineNumber":341,"sourceCode":"    response: GenerateContentResponse,\n    model: str,\n) -> CreateMessageResult:\n    \"\"\"Convert Google GenAI response to CreateMessageResult (no tools).\"\"\"\n    if not (text := response.text):\n        candidate = _get_candidate_from_response(response)\n        # Check if the response only contained thinking\n        has_thoughts = (\n            candidate.content\n            and candidate.content.parts\n            and all(getattr(p, \"thought\", False) for p in candidate.content.parts)\n        )\n        if has_thoughts:\n            msg = (\n                \"Model returned only thinking/reasoning content with no response text.\"\n            )\n        else:\n            msg = f\"No content in response (finish_reason={candidate.finish_reason})\"\n        raise ValueError(msg)\n\n    return CreateMessageResult(\n        content=TextContent(type=\"text\", text=text),\n        role=\"assistant\",\n        model=model,\n    )\n\n\ndef _response_to_result_with_tools(\n    response: GenerateContentResponse,\n    model: str,\n) -> CreateMessageResultWithTools:\n    \"\"\"Convert Google GenAI response to CreateMessageResultWithTools.\"\"\"\n    candidate = _get_candidate_from_response(response)\n\n    # Determine stop reason and check for function calls\n    stop_reason: StopReason\n    finish_reason = candidate.finish_reason","sourceCodeStart":323,"sourceCodeEnd":359,"githubUrl":"https://github.com/PrefectHQ/fastmcp/blob/1f021142978e0861cd910c8df4e8074bc7cf3978/fastmcp_slim/fastmcp/client/sampling/handlers/google_genai.py#L323-L359","documentation":"On the non-tool sampling path, the response candidate had no usable text content. The error distinguishes two cases: the model emitted only 'thought' (reasoning) parts, or the response contained no content at all (with the finish_reason reported). Raised because a CreateMessageResult requires text content.","triggerScenarios":"Calling Client.sample() through GoogleGenAIHandler.__call__ when the model returns only thinking/reasoning parts (e.g. a thinking model with thinking enabled and no final answer), or the candidate finished without producing text (finish_reason like SAFETY, RECITATION, or empty).","commonSituations":"Using thinking-capable Gemini models where reasoning output consumed the whole budget; safety filter stopping generation before any text; max tokens consumed by thoughts; malformed prompt producing no output.","solutions":["Disable or reduce thinking/reasoning config (thinking_config with thinking_budget) so the model produces a final text answer.","Check candidate.finish_reason and adjust the prompt or safety settings accordingly.","Increase max_tokens if generation was truncated before text was emitted.","Catch the ValueError and retry or fall back to another sampling handler."],"exampleFix":"// before\nGenerateContentConfig(thinking_config=ThinkingConfig(thinking_budget=8192))\n// after\nGenerateContentConfig(thinking_config=ThinkingConfig(thinking_budget=0))  # or raise max_tokens","handlingStrategy":"try-catch","validationCode":"null","typeGuard":"null","tryCatchPattern":"try:\n    result = await client.sample(...)\nexcept ValueError as e:\n    if 'only thinking' in str(e) or 'No content in response' in str(e):\n        result = await client.sample(messages=messages, max_tokens=increased, ...)  # or disable thinking\n    else:\n        raise","preventionTips":["Allocate enough max_tokens for thinking models to emit a final answer.","Disable or cap thinking budget when you only need final text.","Log finish_reason from failures to tune prompts/safety settings."],"tags":["sampling","google-genai","empty-response"],"backgroundTag":"empty-completion-response","analyzedSha":"1f021142978e0861cd910c8df4e8074bc7cf3978","analyzedAt":"2026-08-29T14:31:16.082Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}