{"record":{"id":"4da31b50b00bb02e","repo":"microsoft/semantic-kernel","slug":"ollama-does-not-support-function-choice-behavior-o","errorCode":null,"errorMessage":"Ollama does not support function choice behavior of type 'required' or 'none' yet.","messagePattern":"Ollama does not support function choice behavior of type 'required' or 'none' yet\\.","errorType":"exception","errorClass":"ServiceInvalidExecutionSettingsError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/ai/ollama/services/ollama_chat_completion.py","lineNumber":133,"sourceCode":"            return str(self.client._client.base_url)\n        return None\n\n    @override\n    def _prepare_chat_history_for_request(\n        self,\n        chat_history: ChatHistory,\n        role_key: str = \"role\",\n        content_key: str = \"content\",\n    ) -> list[Message]:\n        return [MESSAGE_CONVERTERS[message.role](message) for message in chat_history.messages]\n\n    @override\n    def _verify_function_choice_settings(self, settings: \"PromptExecutionSettings\") -> None:\n        if settings.function_choice_behavior and settings.function_choice_behavior.type_ in [\n            FunctionChoiceType.REQUIRED,\n            FunctionChoiceType.NONE,\n        ]:\n            raise ServiceInvalidExecutionSettingsError(\n                \"Ollama does not support function choice behavior of type 'required' or 'none' yet.\"\n            )\n\n    @override\n    def _update_function_choice_settings_callback(\n        self,\n    ) -> Callable[[\"FunctionCallChoiceConfiguration\", \"PromptExecutionSettings\", FunctionChoiceType], None]:\n        return update_settings_from_function_choice_configuration\n\n    @override\n    def _reset_function_choice_settings(self, settings: \"PromptExecutionSettings\") -> None:\n        if hasattr(settings, \"tools\"):\n            settings.tools = None\n\n    @override\n    @trace_chat_completion(OllamaBase.MODEL_PROVIDER_NAME)\n    async def _inner_get_chat_message_contents(\n        self,","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/ai/ollama/services/ollama_chat_completion.py#L115-L151","documentation":"Raised as ServiceInvalidExecutionSettingsError (a subclass of ServiceResponseException) in `_verify_function_choice_settings` when the configured `settings.function_choice_behavior.type_` is FunctionChoiceType.REQUIRED or FunctionChoiceType.NONE. The current Ollama connector only supports AUTO (or none) for tool/function calling; 'required' (force a tool call) and 'none' (forbid tools) are not implemented against the Ollama API.","triggerScenarios":"Configuring the chat settings / prompt execution with `FunctionChoiceBehavior.Required` or `FunctionChoiceBehavior.None` (or required=True / type_='required') and then invoking chat on an OllamaChatCompletion service. The check runs during settings verification, before the request is sent.","commonSituations":"Porting an OpenAI/Azure agent config (which supports required/none) to Ollama unchanged; using the kernel's function-calling auto-invoke with a required behavior; explicitly disabling tools with FunctionChoiceType.NONE.","solutions":["Use FunctionChoiceBehavior.Auto (or omit the behavior) for Ollama tool calling.","If you need required/none semantics, switch to a connector that supports them (OpenAI/Azure) or remove tools from the request.","Gating: check the service type before applying required/none behavior."],"exampleFix":"# before\nfrom semantic_kernel.connectors.ai.function_choice_behavior import FunctionChoiceBehavior\nsettings.function_choice_behavior = FunctionChoiceBehavior.Required()\n\n# after - Auto is supported by Ollama\nsettings.function_choice_behavior = FunctionChoiceBehavior.Auto(auto_invoke=True)","handlingStrategy":"validation","validationCode":"from semantic_kernel.connectors.ai.function_choice_behavior import FunctionChoiceBehavior\nfrom semantic_kernel.connectors.ai.function_choice_behavior import FunctionChoiceType\nif isinstance(svc, OllamaChatCompletion):\n    fcb = settings.function_choice_behavior\n    assert not fcb or fcb.type_ == FunctionChoiceType.AUTO, \\\n        'Ollama supports only Auto function choice behavior'","typeGuard":"from semantic_kernel.connectors.ai.function_choice_behavior import FunctionChoiceType\n\ndef is_ollama_supported_fcb(settings) -> bool:\n    fcb = getattr(settings, 'function_choice_behavior', None)\n    return not fcb or fcb.type_ == FunctionChoiceType.AUTO","tryCatchPattern":"from semantic_kernel.exceptions import ServiceInvalidExecutionSettingsError\ntry:\n    await svc.get_chat_message_contents(chat_history, settings)\nexcept ServiceInvalidExecutionSettingsError as e:\n    if \"does not support function choice behavior\" in str(e):\n        settings.function_choice_behavior = None  # or Auto\n        await svc.get_chat_message_contents(chat_history, settings)\n    else:\n        raise","preventionTips":["Use FunctionChoiceBehavior.Auto (or no tools) for Ollama; required/none are unsupported.","When porting OpenAI/Azure configs to Ollama, downgrade function choice behavior.","Gate tool/behavior config on the connector type before applying."],"tags":["ollama","chat-completion","function-calling","tools","execution-settings","not-supported"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}