microsoft/semantic-kernel · error · NotSupportedException

The provided response modalities '{executionSettings.Modalit

Error message

The provided response modalities '{executionSettings.Modalities?.GetType()}' is not supported.

What it means

Thrown inside GetResponseModalities when executionSettings.Modalities is a JsonElement that is neither a String ValueKind nor an Array ValueKind (e.g. Number, Object, Boolean, Null falls through earlier), so the code reports the actual runtime type of executionSettings.Modalities as unsupported. This is the catch-all for an unrecognized modality JSON shape.

Source

Thrown at dotnet/src/Connectors/Connectors.AzureOpenAI/Core/AzureClientCore.ChatCompletion.cs:214

                }

                throw new NotSupportedException($"The provided response modalities '{modalityString}' is not supported.");
            }

            if (responseModalitiesElement.ValueKind == JsonValueKind.Array)
            {
                try
                {
                    var modalitiesEnumeration = JsonSerializer.Deserialize<IEnumerable<string>>(responseModalitiesElement.GetRawText())!;
                    return ParseResponseModalitiesEnumerable(modalitiesEnumeration);
                }
                catch (JsonException ex)
                {
                    throw new NotSupportedException("The provided response modalities JSON array may only contain strings.", ex);
                }
            }

            throw new NotSupportedException($"The provided response modalities '{executionSettings.Modalities?.GetType()}' is not supported.");
        }

        return ChatResponseModalities.Default;
    }

    /// <summary>
    /// Gets the audio options from the execution settings.
    /// </summary>
    /// <param name="executionSettings">The execution settings.</param>
    /// <returns>The audio options as a <see cref="ChatAudioOptions"/> object.</returns>
    private static ChatAudioOptions GetAudioOptions(OpenAIPromptExecutionSettings executionSettings)
    {
        if (executionSettings.Audio is ChatAudioOptions audioOptions)
        {
            return audioOptions;
        }

        if (executionSettings.Audio is JsonElement audioOptionsElement)

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Provide Modalities as a ChatResponseModalities flags value, a valid enum-name string, an IEnumerable<string>, or a JSON string/array token — never a JSON object/number.
  2. Correct the config so 'modalities' is a string or array of strings.
  3. Validate the JSON token kind of modalities before binding.

Example fix

// before (config)
{ "modalities": { "text": true } }
// throws: The provided response modalities 'System.Text.Json.JsonElement' is not supported.

// after
{ "modalities": "Text" }
Defensive patterns

Strategy: validation

Validate before calling

static bool IsValidModalitiesJson(JsonElement el)
    => el.ValueKind is JsonValueKind.String or JsonValueKind.Array;

// before binding
if (settings.Modalities is JsonElement je && !IsValidModalitiesJson(je))
    throw new ArgumentException("'modalities' JSON must be a string or an array of strings.");

Type guard

bool IsAcceptableModalitiesJson(JsonElement el)
    => el.ValueKind is JsonValueKind.String or JsonValueKind.Array;

Try / catch

try { /* kernel call */ }
catch (NotSupportedException ex) when (ex.Message.Contains("response modalities") && ex.Message.Contains("is not supported"))
{ throw new ConfigurationException("Unsupported modalities JSON shape; use a string or array of enum names.", ex); }

Prevention

When it happens

Trigger: executionSettings.Modalities is a JsonElement whose ValueKind is Object or Number or True/False — e.g. {"modalities": {"text": true}} or {"modalities": 1}. None of the string/array branches match, so the type is reported as unsupported.

Common situations: Config schema drift sending a JSON object or number where an enum string/array was expected. Programmatic settings assembly assigning a numeric/object JSON value to Modalities.

Related errors


AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13). Data as JSON: /api/errors/738715dadd20e7f1. Report an issue: GitHub.