{"record":{"id":"8fc6fcdb28101295","repo":"microsoft/semantic-kernel","slug":"the-provided-response-modalities-json-array-may-on","errorCode":null,"errorMessage":"The provided response modalities JSON array may only contain strings.","messagePattern":"The provided response modalities JSON array may only contain strings\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Connectors/Connectors.AzureOpenAI/Core/AzureClientCore.ChatCompletion.cs","lineNumber":210,"sourceCode":"                var modalityString = responseModalitiesElement.GetString();\n                if (Enum.TryParse<ChatResponseModalities>(modalityString, true, out var parsedResponseModalities))\n                {\n                    return parsedResponseModalities;\n                }\n\n                throw new NotSupportedException($\"The provided response modalities '{modalityString}' is not supported.\");\n            }\n\n            if (responseModalitiesElement.ValueKind == JsonValueKind.Array)\n            {\n                try\n                {\n                    var modalitiesEnumeration = JsonSerializer.Deserialize<IEnumerable<string>>(responseModalitiesElement.GetRawText())!;\n                    return ParseResponseModalitiesEnumerable(modalitiesEnumeration);\n                }\n                catch (JsonException ex)\n                {\n                    throw new NotSupportedException(\"The provided response modalities JSON array may only contain strings.\", ex);\n                }\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    private static ChatAudioOptions GetAudioOptions(OpenAIPromptExecutionSettings executionSettings)\n    {\n        if (executionSettings.Audio is ChatAudioOptions audioOptions)\n        {","sourceCodeStart":192,"sourceCodeEnd":228,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/src/Connectors/Connectors.AzureOpenAI/Core/AzureClientCore.ChatCompletion.cs#L192-L228","documentation":"Thrown inside GetResponseModalities when executionSettings.Modalities is a JsonElement of ValueKind Array but deserializing it to IEnumerable<string> throws a JsonException — i.e. the array contains non-string elements (numbers, objects, booleans, null). The JsonException is wrapped in a NotSupportedException.","triggerScenarios":"JSON config with \"modalities\": [\"Text\", 1] or \"modalities\": [\"Text\", {\"x\":1}] or \"modalities\": [\"Text\", null]. JsonSerializer.Deserialize<IEnumerable<string>> throws on the non-string element.","commonSituations":"Hand-editing config and accidentally mixing types in the modalities array. Programmatic generation of the JSON array with numeric/boolean values. Schema drift between producer and consumer.","solutions":["Ensure the JSON 'modalities' array contains only string elements.","Validate the array element kinds before binding to settings.","Use valid enum names as strings inside the array."],"exampleFix":"// before (config)\n{ \"modalities\": [\"Text\", 1] }\n// throws: The provided response modalities JSON array may only contain strings.\n\n// after\n{ \"modalities\": [\"Text\", \"Audio\"] }","handlingStrategy":"validation","validationCode":"static bool IsStringArray(JsonElement el)\n{\n    if (el.ValueKind != JsonValueKind.Array) return false;\n    foreach (var item in el.EnumerateArray())\n        if (item.ValueKind != JsonValueKind.String) return false;\n    return true;\n}","typeGuard":"bool IsModalityStringArray(JsonElement el)\n    => el.ValueKind == JsonValueKind.Array && el.EnumerateArray().All(i => i.ValueKind == JsonValueKind.String);","tryCatchPattern":"try { /* kernel call */ }\ncatch (NotSupportedException ex) when (ex.Message.Contains(\"JSON array may only contain strings\"))\n{ throw new ConfigurationException(\"'modalities' array must contain only string modality names.\", ex); }","preventionTips":["Ensure every element of a JSON modalities array is a string.","Validate array element kinds before binding settings.","Use valid enum names as the array entries."],"tags":["azure-openai","execution-settings","modalities","json","configuration","csharp"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}