{"record":{"id":"bf114da97ed14d43","repo":"PrefectHQ/fastmcp","slug":"no-response-for-completion","errorCode":null,"errorMessage":"No response for completion","messagePattern":"No response for completion","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"fastmcp_slim/fastmcp/client/sampling/handlers/openai.py","lineNumber":392,"sourceCode":"                    )\n                openai_messages.append(\n                    ChatCompletionUserMessageParam(\n                        role=\"user\",\n                        content=[_audio_content_to_openai_part(content)],\n                    )\n                )\n                continue\n\n            raise ValueError(f\"Unsupported content type: {type(content)}\")\n\n        return openai_messages\n\n    @staticmethod\n    def _chat_completion_to_create_message_result(\n        chat_completion: ChatCompletion,\n    ) -> CreateMessageResult:\n        if len(chat_completion.choices) == 0:\n            raise ValueError(\"No response for completion\")\n\n        first_choice = chat_completion.choices[0]\n\n        if content := first_choice.message.content:\n            return CreateMessageResult(\n                content=TextContent(type=\"text\", text=content),\n                role=\"assistant\",\n                model=chat_completion.model,\n            )\n\n        raise ValueError(\"No content in response from completion\")\n\n    def _select_model_from_preferences(\n        self, model_preferences: ModelPreferences | str | list[str] | None\n    ) -> ChatModel:\n        for model_option in self._iter_models_from_preferences(model_preferences):\n            if model_option in get_args(ChatModel):\n                chosen_model: ChatModel = model_option  # type: ignore[assignment]  # ty:ignore[invalid-assignment]","sourceCodeStart":374,"sourceCodeEnd":410,"githubUrl":"https://github.com/PrefectHQ/fastmcp/blob/1f021142978e0861cd910c8df4e8074bc7cf3978/fastmcp_slim/fastmcp/client/sampling/handlers/openai.py#L374-L410","documentation":"After receiving a ChatCompletion from OpenAI, this converter requires at least one choice. If chat_completion.choices is an empty list, it cannot construct a CreateMessageResult and raises this ValueError.","triggerScenarios":"OpenAI returns a ChatCompletion with zero choices (typically with finish_reason set or a content filter / error payload that still parses as a completion) and it is passed to _chat_completion_to_create_message_result.","commonSituations":"Content filter blocking the entire response; API returning an empty choices array due to service degradation; n=0 configuration upstream; mocked/test clients returning empty completions.","solutions":["Log chat_completion.model, id, and finish info to identify why the API returned no choices, then retry the sampling request.","Check the OpenAI account/org for content-filter or moderation flags that may empty the response.","Catch the ValueError and fall back to another sampling handler or provider.","Add a pre-check: if not completion.choices: retry or raise a clearer domain error before calling the handler."],"exampleFix":"// before\nresult = await sampling_handler(messages, params)\n// after\ntry:\n    result = await sampling_handler(messages, params)\nexcept ValueError as e:\n    if 'No response for completion' in str(e):\n        result = await sampling_handler(messages, params)  # retry once\n    else:\n        raise","handlingStrategy":"retry","validationCode":"def has_choices(completion) -> bool:\n    return bool(getattr(completion, 'choices', None))","typeGuard":"def is_usable_completion(completion) -> bool:\n    return len(getattr(completion, 'choices', [])) > 0","tryCatchPattern":"try:\n    result = await sampling_handler(messages, params)\nexcept ValueError as e:\n    if str(e) == 'No response for completion':\n        result = await sampling_handler(messages, params)  # retry with backoff\n    else:\n        raise","preventionTips":["Retry once with backoff on empty-choice responses","Log completion id/finish metadata for provider diagnostics","Check for content-filter flags on the OpenAI account","Use a fallback sampling handler for critical paths"],"tags":["openai","sampling","empty-response","api"],"backgroundTag":"empty-model-response","analyzedSha":"1f021142978e0861cd910c8df4e8074bc7cf3978","analyzedAt":"2026-08-29T14:31:16.082Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}