{"record":{"id":"625ba7fba5b2fe6d","repo":"microsoft/semantic-kernel","slug":"no-message-content-found-in-response-part","errorCode":null,"errorMessage":"No message content found in response part.","messagePattern":"No message content found in response part\\.","errorType":"exception","errorClass":"ServiceInvalidResponseError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/ai/ollama/services/ollama_chat_completion.py","lineNumber":312,"sourceCode":"                        name=tool_call.get(\"function\").get(\"name\"),\n                        arguments=tool_call.get(\"function\").get(\"arguments\"),\n                    )\n                )\n\n        return ChatMessageContent(\n            role=AuthorRole.ASSISTANT,\n            items=items,\n            inner_content=response,\n            metadata=self._get_metadata_from_response(response),\n        )\n\n    def _create_streaming_chat_message_content(\n        self, part: Mapping[str, Any], function_invoke_attempt: int\n    ) -> StreamingChatMessageContent:\n        \"\"\"Create a streaming chat message content from the response part.\"\"\"\n        items: list[STREAMING_ITEM_TYPES] = []\n        if not (message := part.get(\"message\", None)):\n            raise ServiceInvalidResponseError(\"No message content found in response part.\")\n\n        if content := message.get(\"content\", None):\n            items.append(\n                StreamingTextContent(\n                    choice_index=0,\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                    )","sourceCodeStart":294,"sourceCodeEnd":330,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/ai/ollama/services/ollama_chat_completion.py#L294-L330","documentation":"Raised as ServiceInvalidResponseError in `_create_streaming_chat_message_content` (the raw Mapping/dict branch of streaming chat) when a streamed part dict has no `'message'` key (`part.get('message', None)` is falsy). The streaming counterpart of error 1117: the part was a dict (passed the 1116 check) but lacks the message envelope.","triggerScenarios":"A streaming chunk dict from Ollama that omits 'message' - e.g. a final/usage chunk, a control/error chunk, or an Ollama streaming schema variant that nests content differently in some chunks.","commonSituations":"Ollama server emits a trailing chunk without a message field; an error chunk mid-stream; an API/SDK version whose streaming schema differs for the last chunk.","solutions":["Log/inspect the offending part (it is the inner_content) to see if it is an error or control chunk.","Ensure the Ollama server and SDK versions match the connector's expected streaming schema.","If some chunks legitimately lack 'message', filter them in a custom client wrapper before yielding.","Verify the model is loaded and healthy (`ollama ps`)."],"exampleFix":"# before - server yields a final {'done': True, ...} chunk with no 'message'\n\n# after - wrap the client to skip message-less parts\nasync def chat(self, **kw):\n    async for part in self._real.chat(**kw):\n        if isinstance(part, Mapping) and not part.get('message'):\n            continue\n        yield part","handlingStrategy":"validation","validationCode":"# In a smoke test, ensure streaming parts carry a message\nasync for part in await svc.client.chat(model=svc.ai_model_id, messages=[...], stream=True):\n    if isinstance(part, dict):\n        # allow message-less parts only if they are clearly terminal/error\n        if not part.get('message'):\n            assert part.get('done') or part.get('error'), f'unexpected part: {part}'","typeGuard":"from collections.abc import Mapping\n\ndef stream_part_has_message(part) -> bool:\n    return isinstance(part, Mapping) and bool(part.get('message'))","tryCatchPattern":"from semantic_kernel.exceptions import ServiceInvalidResponseError\ntry:\n    async for chunk in svc._inner_get_streaming_chat_message_contents(chat_history, settings):\n        ...\nexcept ServiceInvalidResponseError as e:\n    if 'No message content found in response part' in str(e):\n        raise RuntimeError('a streaming chunk lacked a message envelope; check server/SDK version') from e\n    raise","preventionTips":["If your server emits message-less chunks, wrap the client to skip them.","Keep Ollama server and SDK versions consistent with the connector.","Add a streaming smoke test asserting each part carries a message (or is terminal)."],"tags":["ollama","streaming","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"}