microsoft/semantic-kernel · error · ServiceResponseException

{type(self)} service failed to complete the prompt

Error message

{type(self)} service failed to complete the prompt

What it means

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__.

Source

Thrown at python/semantic_kernel/connectors/ai/mistral_ai/services/mistral_ai_chat_completion.py:143

    @override
    @trace_chat_completion(MistralAIBase.MODEL_PROVIDER_NAME)
    async def _inner_get_chat_message_contents(
        self,
        chat_history: "ChatHistory",
        settings: "PromptExecutionSettings",
    ) -> list["ChatMessageContent"]:
        if not isinstance(settings, MistralAIChatPromptExecutionSettings):
            settings = self.get_prompt_execution_settings_from_settings(settings)
        assert isinstance(settings, MistralAIChatPromptExecutionSettings)  # nosec

        settings.ai_model_id = settings.ai_model_id or self.ai_model_id
        settings.messages = self._prepare_chat_history_for_request(chat_history)

        try:
            response = await self.async_client.chat.complete_async(**settings.prepare_settings_dict())
        except Exception as ex:
            raise ServiceResponseException(
                f"{type(self)} service failed to complete the prompt",
                ex,
            ) from ex

        if isinstance(response, ChatCompletionResponse):
            response_metadata = self._get_metadata_from_response(response)
            # If there are no choices, return an empty list
            if isinstance(response.choices, list) and len(response.choices) > 0:
                return [
                    self._create_chat_message_content(response, choice, response_metadata)
                    for choice in response.choices
                ]
        return []

    @override
    @trace_streaming_chat_completion(MistralAIBase.MODEL_PROVIDER_NAME)
    async def _inner_get_streaming_chat_message_contents(
        self,

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Inspect the chained __cause__ to identify the specific Mistral API error (auth, 429, 4xx, timeout).
  2. For auth errors, refresh/validate the API key and settings.
  3. For rate limits (429), implement backoff/retry with jitter.
  4. For malformed-request errors, validate messages/model id and reduce payload size.

Example fix

# before
resp = await svc.get_chat_message_contents(history, settings)  # may raise
# after
try:
    resp = await svc.get_chat_message_contents(history, settings)
except ServiceResponseException as e:
    logger.error('mistral failed: %r', e.__cause__)
    # backoff / retry / fallback model
Defensive patterns

Strategy: try-catch

Validate before calling

assert settings.ai_model_id, 'model id required'
assert chat_history.messages, 'chat history must not be empty'

Try / catch

try:
    resp = await svc.get_chat_message_contents(history, settings)
except ServiceResponseException as e:
    cause = e.__cause__
    logger.error('mistral chat failed: %r', cause)
    # branch on auth / 429 / timeout and retry/backoff accordingly
    raise

Prevention

When it happens

Trigger: 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.

Common situations: Expired/revoked API key. Exceeding rate limits. Requesting an unavailable model. Sending too-large/malformed chat history. Transient network issues.

Related errors


AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13). Data as JSON: /api/errors/5dc892732c3ea261. Report an issue: GitHub.