{"record":{"id":"5dc892732c3ea261","repo":"microsoft/semantic-kernel","slug":"type-self-service-failed-to-complete-the-prompt","errorCode":null,"errorMessage":"{type(self)} service failed to complete the prompt","messagePattern":"(.+?) service failed to complete the prompt","errorType":"exception","errorClass":"ServiceResponseException","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/ai/mistral_ai/services/mistral_ai_chat_completion.py","lineNumber":143,"sourceCode":"\n    @override\n    @trace_chat_completion(MistralAIBase.MODEL_PROVIDER_NAME)\n    async def _inner_get_chat_message_contents(\n        self,\n        chat_history: \"ChatHistory\",\n        settings: \"PromptExecutionSettings\",\n    ) -> list[\"ChatMessageContent\"]:\n        if not isinstance(settings, MistralAIChatPromptExecutionSettings):\n            settings = self.get_prompt_execution_settings_from_settings(settings)\n        assert isinstance(settings, MistralAIChatPromptExecutionSettings)  # nosec\n\n        settings.ai_model_id = settings.ai_model_id or self.ai_model_id\n        settings.messages = self._prepare_chat_history_for_request(chat_history)\n\n        try:\n            response = await self.async_client.chat.complete_async(**settings.prepare_settings_dict())\n        except Exception as ex:\n            raise ServiceResponseException(\n                f\"{type(self)} service failed to complete the prompt\",\n                ex,\n            ) from ex\n\n        if isinstance(response, ChatCompletionResponse):\n            response_metadata = self._get_metadata_from_response(response)\n            # If there are no choices, return an empty list\n            if isinstance(response.choices, list) and len(response.choices) > 0:\n                return [\n                    self._create_chat_message_content(response, choice, response_metadata)\n                    for choice in response.choices\n                ]\n        return []\n\n    @override\n    @trace_streaming_chat_completion(MistralAIBase.MODEL_PROVIDER_NAME)\n    async def _inner_get_streaming_chat_message_contents(\n        self,","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/ai/mistral_ai/services/mistral_ai_chat_completion.py#L125-L161","documentation":"Raised by MistralAIChatCompletion._inner_get_chat_message_contents when the underlying async_client.chat.complete_async(...) call throws any Exception. The connector wraps all failures (network, auth, rate-limit, bad request, client errors) into a ServiceResponseException chained from the original cause, so the real API error is in __cause__.","triggerScenarios":"Calling Mistral chat completion under failing conditions: invalid/expired API key, rate limiting, malformed request payload, model unavailable, network timeout, or any SDK-level exception from the Mistral client.","commonSituations":"Expired/revoked API key. Exceeding rate limits. Requesting an unavailable model. Sending too-large/malformed chat history. Transient network issues.","solutions":["Inspect the chained __cause__ to identify the specific Mistral API error (auth, 429, 4xx, timeout).","For auth errors, refresh/validate the API key and settings.","For rate limits (429), implement backoff/retry with jitter.","For malformed-request errors, validate messages/model id and reduce payload size."],"exampleFix":"# before\nresp = await svc.get_chat_message_contents(history, settings)  # may raise\n# after\ntry:\n    resp = await svc.get_chat_message_contents(history, settings)\nexcept ServiceResponseException as e:\n    logger.error('mistral failed: %r', e.__cause__)\n    # backoff / retry / fallback model","handlingStrategy":"try-catch","validationCode":"assert settings.ai_model_id, 'model id required'\nassert chat_history.messages, 'chat history must not be empty'","typeGuard":null,"tryCatchPattern":"try:\n    resp = await svc.get_chat_message_contents(history, settings)\nexcept ServiceResponseException as e:\n    cause = e.__cause__\n    logger.error('mistral chat failed: %r', cause)\n    # branch on auth / 429 / timeout and retry/backoff accordingly\n    raise","preventionTips":["Always inspect e.__cause__ to classify the failure (auth, rate-limit, timeout).","Implement exponential backoff for 429/network errors.","Validate API key freshness and request payload size before calling."],"tags":["mistral-ai","chat-completion","runtime","network"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}