microsoft/semantic-kernel · error · ValueError
Tool message must have a function result content item.
Error message
Tool message must have a function result content item.
What it means
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.
Source
Thrown at python/semantic_kernel/connectors/ai/ollama/services/utils.py:102
}
for tool_call in tool_calls
]
return assistant_message
def _format_tool_message(message: ChatMessageContent) -> Message:
"""Format a tool message to the expected object for the client.
Args:
message: The tool message.
Returns:
The formatted tool message.
"""
function_result_items = [item for item in message.items if isinstance(item, FunctionResultContent)]
if not function_result_items:
raise ValueError("Tool message must have a function result content item.")
return Message(role="tool", content=str(function_result_items[0].result))
MESSAGE_CONVERTERS: dict[AuthorRole, Callable[[ChatMessageContent], Message]] = {
AuthorRole.SYSTEM: _format_system_message,
AuthorRole.USER: _format_user_message,
AuthorRole.ASSISTANT: _format_assistant_message,
AuthorRole.TOOL: _format_tool_message,
}
def update_settings_from_function_choice_configuration(
function_choice_configuration: "FunctionCallChoiceConfiguration",
settings: "PromptExecutionSettings",
type: FunctionChoiceType,
) -> None:
"""Update the settings from a FunctionChoiceConfiguration.View on GitHub (pinned to c028a0c7dc)
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
Example fix
// before ChatMessageContent(role=AuthorRole.TOOL, items=[TextContent(text='42')]) // after ChatMessageContent(role=AuthorRole.TOOL, items=[FunctionResultContent(id='call_1', name='calc', result='42')])
Defensive patterns
Strategy: validation
Validate before calling
from semantic_kernel.contents import FunctionResultContent
def validate_tool_message(message):
has_result = any(
isinstance(item, FunctionResultContent) for item in message.items
)
if not has_result:
raise ValueError('Tool message must contain a FunctionResultContent item') Type guard
from semantic_kernel.contents import FunctionResultContent
def is_valid_tool_message(message) -> bool:
return any(
isinstance(item, FunctionResultContent) for item in message.items
) Try / catch
try:
response = await chat.get_chat_message_contents(chat_history=history, settings=settings)
except ValueError as e:
if 'function result content item' in str(e):
logger.error('A tool message is missing its FunctionResultContent; rebuilding')
raise Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Image item must contain data encoded as base64.
- Image must be encoded as base64.
- Please provide valid Ollama configuration in appsettings.Dev
- No function result provided in the tool message.
- No IOllamaApiClient implementations found in the service col
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/bff02b213834c2b6.
Report an issue: GitHub.