microsoft/semantic-kernel · error · ValueError
The service must support structured output.
Error message
The service must support structured output.
What it means
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.
Source
Thrown at python/semantic_kernel/agents/orchestration/tools.py:42
Args:
target_structure (type): The target structure to transform the output into.
service (ChatCompletionClientBase): The chat completion service to use for the transformation. This service
must support structured output.
prompt_execution_settings (PromptExecutionSettings, optional): The settings to use for the prompt execution.
Returns:
Callable[[DefaultTypeAlias], Awaitable[BaseModel]]: A function that takes the output of
the chat completion service and transforms it into the target structure.
"""
kernel = Kernel()
kernel.add_service(service)
settings = kernel.get_prompt_execution_settings_from_service_id(service.service_id)
if prompt_execution_settings:
settings.update_from_prompt_execution_settings(prompt_execution_settings)
if not hasattr(settings, "response_format"):
raise ValueError("The service must support structured output.")
settings.response_format = target_structure
chat_history = ChatHistory(
system_message=(
"Try your best to summarize the conversation into structured format:\n"
f"{target_structure.model_json_schema()}."
),
)
async def output_transform(output: DefaultTypeAlias) -> BaseModel:
"""Transform the output of the chat completion service into the target structure."""
if isinstance(output, ChatMessageContent):
chat_history.add_message(output)
elif isinstance(output, list) and all(isinstance(item, ChatMessageContent) for item in output):
for item in output:
chat_history.add_message(item)
else:
raise ValueError(f"Output must be {DefaultTypeAlias}.")View on GitHub (pinned to c028a0c7dc)
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.
Example fix
// before from semantic_kernel.connectors.ai.open_ai import OpenAIChatCompletion service = OpenAIChatCompletion(service_id="local", ai_model_id="x", ...) # settings w/o response_format tool = get_response_from_structured_output_tool(service, MyModel) // after from semantic_kernel.connectors.ai.open_ai import AzureChatCompletion service = AzureChatCompletion(service_id="az", deployment_name="gpt-4o", endpoint=..., api_key=...) tool = get_response_from_structured_output_tool(service, MyModel)
Defensive patterns
Strategy: validation
Validate before calling
from semantic_kernel import Kernel
def service_supports_structured_output(service) -> bool:
kernel = Kernel(); kernel.add_service(service)
settings = kernel.get_prompt_execution_settings_from_service_id(service.service_id)
return hasattr(settings, "response_format") Type guard
def has_response_format(service) -> bool:
try:
from semantic_kernel import Kernel
k = Kernel(); k.add_service(service)
return hasattr(k.get_prompt_execution_settings_from_service_id(service.service_id), "response_format")
except Exception:
return False Try / catch
try:
tool = get_response_from_structured_output_tool(service, MyModel)
except ValueError as e:
if "structured output" in str(e):
service = AzureChatCompletion(...) # switch to a supporting service
tool = get_response_from_structured_output_tool(service, MyModel)
else:
raise Prevention
- 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.
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- Output must be {DefaultTypeAlias}.
- Unable to transform result into {typeof(TOutput).Name}
- A complete listen_for condition is required for orchestratio
- At least one then action is required for orchestration steps
- The service must support structured output.
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/2354ee6bd80444b3.
Report an issue: GitHub.