{"record":{"id":"bff02b213834c2b6","repo":"microsoft/semantic-kernel","slug":"tool-message-must-have-a-function-result-content-i","errorCode":null,"errorMessage":"Tool message must have a function result content item.","messagePattern":"Tool message must have a function result content item\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/ai/ollama/services/utils.py","lineNumber":102,"sourceCode":"            }\n            for tool_call in tool_calls\n        ]\n\n    return assistant_message\n\n\ndef _format_tool_message(message: ChatMessageContent) -> Message:\n    \"\"\"Format a tool message to the expected object for the client.\n\n    Args:\n        message: The tool message.\n\n    Returns:\n        The formatted tool message.\n    \"\"\"\n    function_result_items = [item for item in message.items if isinstance(item, FunctionResultContent)]\n    if not function_result_items:\n        raise ValueError(\"Tool message must have a function result content item.\")\n\n    return Message(role=\"tool\", content=str(function_result_items[0].result))\n\n\nMESSAGE_CONVERTERS: dict[AuthorRole, Callable[[ChatMessageContent], Message]] = {\n    AuthorRole.SYSTEM: _format_system_message,\n    AuthorRole.USER: _format_user_message,\n    AuthorRole.ASSISTANT: _format_assistant_message,\n    AuthorRole.TOOL: _format_tool_message,\n}\n\n\ndef update_settings_from_function_choice_configuration(\n    function_choice_configuration: \"FunctionCallChoiceConfiguration\",\n    settings: \"PromptExecutionSettings\",\n    type: FunctionChoiceType,\n) -> None:\n    \"\"\"Update the settings from a FunctionChoiceConfiguration.","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/ai/ollama/services/utils.py#L84-L120","documentation":"Raised inside _format_tool_message when a tool-role ChatMessageContent has no items that are instances of FunctionResultContent. The Ollama API expects tool messages to carry a function result; the formatter extracts the result from the first FunctionResultContent item. Without one, it cannot build the payload. Raised as a plain ValueError.","triggerScenarios":"Constructing a ChatMessageContent with role=AuthorRole.TOOL but with items that do not include a FunctionResultContent — e.g. only TextContent items, or an empty items list. Triggered during message formatting for any Ollama request containing a tool message.","commonSituations":"Manually building tool responses instead of using the function-calling result pipeline; serializing/deserializing tool messages and losing the FunctionResultContent type; adding a TextContent to a tool message by mistake.","solutions":["Ensure tool messages contain at least one FunctionResultContent item","Use FunctionResultContent(id=..., name=..., result=...) when constructing tool responses","Check message.items before adding the message to chat history"],"exampleFix":"// before\nChatMessageContent(role=AuthorRole.TOOL, items=[TextContent(text='42')])\n// after\nChatMessageContent(role=AuthorRole.TOOL, items=[FunctionResultContent(id='call_1', name='calc', result='42')])","handlingStrategy":"validation","validationCode":"from semantic_kernel.contents import FunctionResultContent\n\ndef validate_tool_message(message):\n    has_result = any(\n        isinstance(item, FunctionResultContent) for item in message.items\n    )\n    if not has_result:\n        raise ValueError('Tool message must contain a FunctionResultContent item')","typeGuard":"from semantic_kernel.contents import FunctionResultContent\n\ndef is_valid_tool_message(message) -> bool:\n    return any(\n        isinstance(item, FunctionResultContent) for item in message.items\n    )","tryCatchPattern":"try:\n    response = await chat.get_chat_message_contents(chat_history=history, settings=settings)\nexcept ValueError as e:\n    if 'function result content item' in str(e):\n        logger.error('A tool message is missing its FunctionResultContent; rebuilding')\n        raise","preventionTips":["Always use FunctionResultContent when constructing tool responses","Add a validation helper that checks every AuthorRole.TOOL message before adding to history","During deserialization, rehydrate tool messages with the correct FunctionResultContent type"],"tags":["ollama","tool-message","function-result","message-formatting"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}