{"record":{"id":"6cc91757f0e839ff","repo":"microsoft/semantic-kernel","slug":"no-message-content-found-in-response","errorCode":null,"errorMessage":"No message content found in response.","messagePattern":"No message content found in response\\.","errorType":"exception","errorClass":"ServiceInvalidResponseError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/ai/ollama/services/ollama_chat_completion.py","lineNumber":279,"sourceCode":"                TextContent(\n                    text=response.message.content,\n                    inner_content=response.message,\n                )\n            )\n        self._parse_tool_calls(response.message.tool_calls, items)\n        return ChatMessageContent(\n            role=AuthorRole.ASSISTANT,\n            items=items,\n            inner_content=response,\n            ai_model_id=self.ai_model_id,\n            metadata=self._get_metadata_from_chat_response(response),\n        )\n\n    def _create_chat_message_content(self, response: Mapping[str, Any]) -> ChatMessageContent:\n        \"\"\"Create a chat message content from the response.\"\"\"\n        items: list[CMC_ITEM_TYPES] = []\n        if not (message := response.get(\"message\", None)):\n            raise ServiceInvalidResponseError(\"No message content found in response.\")\n\n        if content := message.get(\"content\", None):\n            items.append(\n                TextContent(\n                    text=content,\n                    inner_content=message,\n                )\n            )\n        if tool_calls := message.get(\"tool_calls\", None):\n            for tool_call in tool_calls:\n                items.append(\n                    FunctionCallContent(\n                        inner_content=tool_call,\n                        ai_model_id=self.ai_model_id,\n                        name=tool_call.get(\"function\").get(\"name\"),\n                        arguments=tool_call.get(\"function\").get(\"arguments\"),\n                    )\n                )","sourceCodeStart":261,"sourceCodeEnd":297,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/ai/ollama/services/ollama_chat_completion.py#L261-L297","documentation":"Raised as ServiceInvalidResponseError in `_create_chat_message_content` (the raw Mapping/dict branch of non-streaming chat) when the response dict has no top-level `'message'` key (`response.get('message', None)` is falsy). The connector cannot locate the assistant message envelope, so it refuses to fabricate content.","triggerScenarios":"The Ollama server returned a dict that lacks the 'message' field - e.g. an error response body, a partial/keep-alive response, or an Ollama API version whose non-streaming schema moved the content under a different key.","commonSituations":"Ollama server returned an error JSON (e.g. {'error':'model not found'}) that the SDK mapped to a dict without 'message'; an API version mismatch; an unexpected response shape from a load endpoint.","solutions":["Check the Ollama server logs / the raw dict inner_content for an 'error' field explaining the real problem.","Confirm the model id exists (`ollama list`) and the server is healthy (`ollama ps`).","Align the Ollama server version with the schema the SDK/connector expects.","If the dict legitimately has no message (error), surface it to the user rather than retrying blindly."],"exampleFix":"# before - server returns {'error': 'model not found'}\nawait svc.get_chat_message_contents(chat_history, settings)\n\n# after - detect error envelope, fetch the model first\nimport subprocess\nsubprocess.run(['ollama','pull','llama3'], check=True)\nawait svc.get_chat_message_contents(chat_history, settings)","handlingStrategy":"validation","validationCode":"# Before relying on the service, confirm it returns a message envelope\nresp = await svc.client.chat(model=svc.ai_model_id, messages=[{'role':'user','content':'hi'}], stream=False)\nif isinstance(resp, dict):\n    assert resp.get('message'), f'response missing message: {resp}'","typeGuard":"from collections.abc import Mapping\n\ndef response_has_message(resp) -> bool:\n    return isinstance(resp, Mapping) and bool(resp.get('message'))","tryCatchPattern":"from semantic_kernel.exceptions import ServiceInvalidResponseError\ntry:\n    resp = await svc.get_chat_message_contents(chat_history, settings)\nexcept ServiceInvalidResponseError as e:\n    if 'No message content found in response' in str(e):\n        # likely an error envelope; fetch raw to inspect\n        raw = await svc.client.chat(model=svc.ai_model_id, messages=[{'role':'user','content':'hi'}], stream=False)\n        raise RuntimeError(f'Ollama returned unexpected body: {raw}') from e\n    raise","preventionTips":["Confirm the model is loaded (`ollama list`, `ollama ps`) before calling.","Inspect raw server responses when behavior is unexpected.","Keep the Ollama server version aligned with the SDK/connector schema."],"tags":["ollama","chat-completion","response-shape","schema","service-invalid-response-error"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}