{"record":{"id":"aedd10f3a0656f4f","repo":"microsoft/semantic-kernel","slug":"response-format-must-be-a-dictionary-a-subclass-o-aedd10","errorCode":null,"errorMessage":"response_format must be a dictionary, a subclass of BaseModel, a Python class/type, or None","messagePattern":"response_format must be a dictionary, a subclass of BaseModel, a Python class/type, or None","errorType":"exception","errorClass":"ServiceInvalidExecutionSettingsError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/ai/azure_ai_inference/azure_ai_inference_prompt_execution_settings.py","lineNumber":82,"sourceCode":"\n        if isinstance(response_format, dict):\n            if response_format.get(\"type\") == \"json_object\":\n                return values\n            if response_format.get(\"type\") == \"json_schema\":\n                json_schema = response_format.get(\"json_schema\")\n                if isinstance(json_schema, dict):\n                    values[\"structured_json_response\"] = True\n                    return values\n                raise ServiceInvalidExecutionSettingsError(\n                    \"If response_format has type 'json_schema', 'json_schema' must be a valid dictionary.\"\n                )\n        if isinstance(response_format, type):\n            if issubclass(response_format, BaseModel):\n                values[\"structured_json_response\"] = True\n            else:\n                values[\"structured_json_response\"] = True\n        else:\n            raise ServiceInvalidExecutionSettingsError(\n                \"response_format must be a dictionary, a subclass of BaseModel, a Python class/type, or None\"\n            )\n\n        return values\n\n\n@experimental\nclass AzureAIInferenceEmbeddingPromptExecutionSettings(PromptExecutionSettings):\n    \"\"\"Azure AI Inference Embedding Prompt Execution Settings.\n\n    Note:\n        `extra_parameters` is a dictionary to pass additional model-specific parameters to the model.\n    \"\"\"\n\n    dimensions: Annotated[int | None, Field(gt=0)] = None\n    encoding_format: Literal[\"base64\", \"binary\", \"float\", \"int8\", \"ubinary\", \"uint8\"] | None = None\n    input_type: Literal[\"text\", \"query\", \"document\"] | None = None\n    extra_parameters: dict[str, str] | None = None","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/ai/azure_ai_inference/azure_ai_inference_prompt_execution_settings.py#L64-L100","documentation":"Raised by the Azure AI Inference settings validator when response_format is not None, not a dict, and not a type/class. The validator accepts a dict (json_object/json_schema), a BaseModel subclass, any plain Python class/type (used as a schema source), or None; any other runtime object (instance, int, list, string) is rejected because it cannot be mapped to a response format.","triggerScenarios":"Passing an instance of a model instead of the class (e.g. MyModel() instead of MyModel); passing a JSON string; passing a list, int, or other non-type object as response_format.","commonSituations":"Instantiating a schema model and passing the instance rather than the class; passing a serialized schema string; copy-paste from examples that used a different library's expected type.","solutions":["Pass the class/type (e.g. MyModel) not an instance (MyModel()).","If you have a dict, use the {'type':'json_schema', ...} or {'type':'json_object'} shapes.","If passing None is acceptable for your call, omit response_format entirely."],"exampleFix":"# before\nsettings.response_format = MyModel()  # instance → error\n\n# after\nsettings.response_format = MyModel  # class → accepted","handlingStrategy":"type-guard","validationCode":"from typing import Any\nfrom pydantic import BaseModel\n\ndef coerce_response_format(rf: Any):\n    if rf is None or isinstance(rf, dict):\n        return rf\n    if isinstance(rf, type) and issubclass(rf, BaseModel):\n        return rf\n    if isinstance(rf, type):\n        return rf\n    raise TypeError(\"response_format must be None, a dict, a BaseModel subclass, or a class/type\")\n\nsettings.response_format = coerce_response_format(candidate)","typeGuard":"from pydantic import BaseModel\nfrom typing import Any\n\ndef is_acceptable_response_format(rf: Any) -> bool:\n    if rf is None:\n        return True\n    if isinstance(rf, dict):\n        return True\n    if isinstance(rf, type) and (issubclass(rf, BaseModel) or True):\n        return True\n    return False","tryCatchPattern":"from semantic_kernel.exceptions import ServiceInvalidExecutionSettingsError\ntry:\n    settings.response_format = candidate\nexcept ServiceInvalidExecutionSettingsError:\n    settings.response_format = MyModel  # fall back to the class","preventionTips":["Pass the class, not an instance.","Validate response_format type before assignment.","Use None or a dict/class — never a string or instance."],"tags":["azure-ai-inference","structured-output","validation","python"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}