{"record":{"id":"09160ea59dbe0c9c","repo":"microsoft/semantic-kernel","slug":"the-provided-response-modalities-executionsettin-09160e","errorCode":null,"errorMessage":"The provided response modalities '{executionSettings.Modalities?.GetType()}' is not supported.","messagePattern":"The provided response modalities '(.+?)' is not supported\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Connectors/Connectors.OpenAI/Core/ClientCore.ChatCompletion.cs","lineNumber":1176,"sourceCode":"            }\n            throw new NotSupportedException($\"The provided response modalities '{responseModalitiesString}' is not supported.\");\n        }\n\n        if (executionSettings.Modalities is JsonElement responseModalitiesElement)\n        {\n            if (responseModalitiesElement.ValueKind == JsonValueKind.String &&\n                Enum.TryParse<ChatResponseModalities>(responseModalitiesElement.GetString(), true, out var parsedResponseModalities))\n            {\n                return parsedResponseModalities;\n            }\n\n            if (responseModalitiesElement.ValueKind == JsonValueKind.Array)\n            {\n                var modalitiesEnumeration = JsonSerializer.Deserialize<IEnumerable<string>>(responseModalitiesElement.GetRawText())!;\n                return ParseResponseModalitiesEnumerable(modalitiesEnumeration);\n            }\n\n            throw new NotSupportedException($\"The provided response modalities '{executionSettings.Modalities?.GetType()}' is not supported.\");\n        }\n\n        return ChatResponseModalities.Default;\n    }\n\n    /// <summary>\n    /// Gets the audio options from the execution settings.\n    /// </summary>\n    /// <param name=\"executionSettings\">The execution settings.</param>\n    /// <returns>The audio options as a <see cref=\"ChatAudioOptions\"/> object.</returns>\n    /// <remarks>\n    /// This method supports converting from various formats:\n    /// <list type=\"bullet\">\n    /// <item><description>A <see cref=\"ChatAudioOptions\"/> object</description></item>\n    /// <item><description>A <see cref=\"JsonElement\"/> containing the serialized audio options</description></item>\n    /// <item><description>A <see cref=\"string\"/> containing the JSON representation of the audio options</description></item>\n    /// </list>\n    /// </remarks>","sourceCodeStart":1158,"sourceCodeEnd":1194,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/src/Connectors/Connectors.OpenAI/Core/ClientCore.ChatCompletion.cs#L1158-L1194","documentation":"Terminal throw in the modalities mapper. After handling ChatResponseModalities enum, IEnumerable<string>, plain string, and JsonElement (string/array kinds), any other runtime type for executionSettings.Modalities is unsupported and its GetType() is reported. This catches mismatches like passing an int, a Dictionary, or a JsonElement of unexpected ValueKind (e.g. Object/Number).","triggerScenarios":"Setting Modalities to a non-supported type: an integer, a JObject/Dictionary, a JsonElement whose ValueKind is Object/Number/False, or a custom object.","commonSituations":"Deserializing settings where Modalities arrived as a JSON object or number; binding from dynamic config; cross-library interop that produces JsonNode instead of JsonElement.","solutions":["Provide Modalities as a ChatResponseModalities enum, a string, an IEnumerable<string>, or a JsonElement that is a string or array.","Normalize the config value into one of those shapes before assigning.","If it is a JsonElement, ensure it is a string or array kind."],"exampleFix":"// before\nsettings.Modalities = 1;\n// after\nsettings.Modalities = ChatResponseModalities.Text;","handlingStrategy":"type-guard","validationCode":"static bool IsSupportedModalities(object? o) => o is ChatResponseModalities or string or IEnumerable<string> or JsonElement;","typeGuard":"static bool IsSupportedModalities(object? o) => o is ChatResponseModalities or string or IEnumerable<string> or JsonElement;","tryCatchPattern":"try { await client.GetChatCompletionAsync(...); }\ncatch (NotSupportedException ex) when (ex.Message.Contains(\"response modalities\")) { settings.Modalities = ChatResponseModalities.Default; }","preventionTips":["Coerce dynamic values to enum/string/array/JsonElement(string|array).","Ensure JSON deserializes Modalities as string or array, not object/number."],"tags":["openai","chat-completion","response-modalities","type-coercion"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}