microsoft/semantic-kernel · error · ServiceInvalidExecutionSettingsError
If response_format has type 'json_schema', 'json_schema' mus
Error message
If response_format has type 'json_schema', 'json_schema' must be a valid dictionary.
What it means
Raised by the Azure AI Inference prompt-execution settings validator when response_format is a dict whose 'type' is 'json_schema' but the nested 'json_schema' value is not a dict. The connector needs the schema as a proper JSON-schema dictionary to enable structured output; a string, None, list, or other type cannot be sent as a valid schema definition.
Source
Thrown at python/semantic_kernel/connectors/ai/azure_ai_inference/azure_ai_inference_prompt_execution_settings.py:73
@model_validator(mode="before")
def validate_response_format_and_set_flag(cls, values: Any) -> Any:
"""Validate the response_format and set structured_json_response accordingly."""
if not isinstance(values, dict):
return values
response_format = values.get("response_format", None)
if response_format is None:
return values
if isinstance(response_format, dict):
if response_format.get("type") == "json_object":
return values
if response_format.get("type") == "json_schema":
json_schema = response_format.get("json_schema")
if isinstance(json_schema, dict):
values["structured_json_response"] = True
return values
raise ServiceInvalidExecutionSettingsError(
"If response_format has type 'json_schema', 'json_schema' must be a valid dictionary."
)
if isinstance(response_format, type):
if issubclass(response_format, BaseModel):
values["structured_json_response"] = True
else:
values["structured_json_response"] = True
else:
raise ServiceInvalidExecutionSettingsError(
"response_format must be a dictionary, a subclass of BaseModel, a Python class/type, or None"
)
return values
@experimental
class AzureAIInferenceEmbeddingPromptExecutionSettings(PromptExecutionSettings):
"""Azure AI Inference Embedding Prompt Execution Settings.View on GitHub (pinned to c028a0c7dc)
Solutions
- Ensure response_format['json_schema'] is a dict — pass a parsed JSON-schema object, e.g. {'type':'json_schema','json_schema': {'name':'X','schema': {...}}} per the Azure AI Inference shape.
- If you have a Pydantic model, either pass the class/type directly (the validator accepts BaseModel subclasses) or call MyModel.model_json_schema() to get the dict.
- Double-check the key name is 'json_schema' (not 'schema') and the value is not a string.
Example fix
# before
settings.response_format = {"type": "json_schema", "json_schema": '{"type":"object"}'}
# after
settings.response_format = {
"type": "json_schema",
"json_schema": {"name": "MyObj", "schema": {"type": "object", "properties": {}}},
} Defensive patterns
Strategy: validation
Validate before calling
def validate_json_schema_response_format(rf):
if isinstance(rf, dict) and rf.get("type") == "json_schema":
assert isinstance(rf.get("json_schema"), dict), \
"json_schema must be a dict when type is 'json_schema'"
return rf
settings.response_format = validate_json_schema_response_format(settings.response_format) Type guard
def is_valid_json_schema_dict(rf) -> bool:
return (
isinstance(rf, dict)
and rf.get("type") == "json_schema"
and isinstance(rf.get("json_schema"), dict)
) Try / catch
from semantic_kernel.exceptions import ServiceInvalidExecutionSettingsError
try:
settings.response_format = rf
except ServiceInvalidExecutionSettingsError as e:
if "json_schema" in str(e):
settings.response_format = {"type": "json_schema", "json_schema": parsed_schema_dict} Prevention
- Always pass the inner schema as a dict, never a JSON string.
- Use the key name 'json_schema' (not 'schema').
- For Pydantic models, pass the class directly or via model_json_schema().
When it happens
Trigger: Passing response_format={'type':'json_schema','json_schema': '<json string>'} or omitting/mis-typing the inner 'json_schema' key (e.g. using 'schema' instead of 'json_schema', or passing a Pydantic class instead of its .model_json_schema() dict).
Common situations: Confusing OpenAI's response_format shape with a custom one; passing a serialized JSON string instead of a parsed dict; using the wrong key name ('schema' vs 'json_schema'); pasting an example that omits the inner dict.
Related errors
- response_format must be a dictionary, a subclass of BaseMode
- Property 'schema' is not initialized in JSON schema response
- Auto invocation of tool calls may only be used with a single
- No FunctionResultContent found in the message items
- The option keys 'name' and 'type' are required for a paramet
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/c47d2bb98a73df5d.
Report an issue: GitHub.