{"record":{"id":"2354ee6bd80444b3","repo":"microsoft/semantic-kernel","slug":"the-service-must-support-structured-output-2354ee","errorCode":null,"errorMessage":"The service must support structured output.","messagePattern":"The service must support structured output\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/agents/orchestration/tools.py","lineNumber":42,"sourceCode":"\n    Args:\n        target_structure (type): The target structure to transform the output into.\n        service (ChatCompletionClientBase): The chat completion service to use for the transformation. This service\n            must support structured output.\n        prompt_execution_settings (PromptExecutionSettings, optional): The settings to use for the prompt execution.\n\n    Returns:\n        Callable[[DefaultTypeAlias], Awaitable[BaseModel]]: A function that takes the output of\n            the chat completion service and transforms it into the target structure.\n    \"\"\"\n    kernel = Kernel()\n    kernel.add_service(service)\n\n    settings = kernel.get_prompt_execution_settings_from_service_id(service.service_id)\n    if prompt_execution_settings:\n        settings.update_from_prompt_execution_settings(prompt_execution_settings)\n    if not hasattr(settings, \"response_format\"):\n        raise ValueError(\"The service must support structured output.\")\n    settings.response_format = target_structure\n\n    chat_history = ChatHistory(\n        system_message=(\n            \"Try your best to summarize the conversation into structured format:\\n\"\n            f\"{target_structure.model_json_schema()}.\"\n        ),\n    )\n\n    async def output_transform(output: DefaultTypeAlias) -> BaseModel:\n        \"\"\"Transform the output of the chat completion service into the target structure.\"\"\"\n        if isinstance(output, ChatMessageContent):\n            chat_history.add_message(output)\n        elif isinstance(output, list) and all(isinstance(item, ChatMessageContent) for item in output):\n            for item in output:\n                chat_history.add_message(item)\n        else:\n            raise ValueError(f\"Output must be {DefaultTypeAlias}.\")","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/agents/orchestration/tools.py#L24-L60","documentation":"Raised by get_response_from_structured_output_tool when the supplied chat completion service's prompt execution settings object has no response_format attribute, meaning the service cannot emit structured/schema-validated output. The helper relies on response_format to force the model to produce JSON conforming to the target pydantic schema, so a service lacking it is unsupported.","triggerScenarios":"Calling get_response_from_structured_output_tool(service, target_structure, ...) with a service whose settings class does not define response_format (e.g. a non-OpenAI service, a custom AzureOpenAI config missing the field, or an older/limited connector).","commonSituations":"Swapping an OpenAI service for a local/Ollama/Azure variant that lacks response_format support, using a chat completion service class that predates structured output support, or passing a service that only supports function-calling (tools) but not response_format.","solutions":["Use a service that supports structured output, e.g. AzureChatPromptExecutionSettings-based services (AzureChatCompletion) or OpenAIChatCompletion.","Upgrade the semantic_kernel connector to a version that exposes response_format on the service's settings.","If your service only supports tool/function calling, use that path instead of get_response_from_structured_output_tool.","Wrap a custom service in a subclass whose settings declare response_format."],"exampleFix":"// before\nfrom semantic_kernel.connectors.ai.open_ai import OpenAIChatCompletion\nservice = OpenAIChatCompletion(service_id=\"local\", ai_model_id=\"x\", ...)  # settings w/o response_format\ntool = get_response_from_structured_output_tool(service, MyModel)\n// after\nfrom semantic_kernel.connectors.ai.open_ai import AzureChatCompletion\nservice = AzureChatCompletion(service_id=\"az\", deployment_name=\"gpt-4o\", endpoint=..., api_key=...)\ntool = get_response_from_structured_output_tool(service, MyModel)","handlingStrategy":"validation","validationCode":"from semantic_kernel import Kernel\n\ndef service_supports_structured_output(service) -> bool:\n    kernel = Kernel(); kernel.add_service(service)\n    settings = kernel.get_prompt_execution_settings_from_service_id(service.service_id)\n    return hasattr(settings, \"response_format\")","typeGuard":"def has_response_format(service) -> bool:\n    try:\n        from semantic_kernel import Kernel\n        k = Kernel(); k.add_service(service)\n        return hasattr(k.get_prompt_execution_settings_from_service_id(service.service_id), \"response_format\")\n    except Exception:\n        return False","tryCatchPattern":"try:\n    tool = get_response_from_structured_output_tool(service, MyModel)\nexcept ValueError as e:\n    if \"structured output\" in str(e):\n        service = AzureChatCompletion(...)  # switch to a supporting service\n        tool = get_response_from_structured_output_tool(service, MyModel)\n    else:\n        raise","preventionTips":["Use AzureChatCompletion or OpenAIChatCompletion for structured output.","Upgrade semantic_kernel connectors to versions exposing response_format.","Check hasattr(settings, 'response_format') before wiring the structured-output tool.","If the service only supports function calling, use that path instead."],"tags":["orchestration","structured-output","service-config","semantic-kernel"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}