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
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).
Source
Thrown at dotnet/src/Connectors/Connectors.OpenAI/Core/ClientCore.ChatCompletion.cs:1176
}
throw new NotSupportedException($"The provided response modalities '{responseModalitiesString}' is not supported.");
}
if (executionSettings.Modalities is JsonElement responseModalitiesElement)
{
if (responseModalitiesElement.ValueKind == JsonValueKind.String &&
Enum.TryParse<ChatResponseModalities>(responseModalitiesElement.GetString(), true, out var parsedResponseModalities))
{
return parsedResponseModalities;
}
if (responseModalitiesElement.ValueKind == JsonValueKind.Array)
{
var modalitiesEnumeration = JsonSerializer.Deserialize<IEnumerable<string>>(responseModalitiesElement.GetRawText())!;
return ParseResponseModalitiesEnumerable(modalitiesEnumeration);
}
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>
/// <remarks>
/// This method supports converting from various formats:
/// <list type="bullet">
/// <item><description>A <see cref="ChatAudioOptions"/> object</description></item>
/// <item><description>A <see cref="JsonElement"/> containing the serialized audio options</description></item>
/// <item><description>A <see cref="string"/> containing the JSON representation of the audio options</description></item>
/// </list>
/// </remarks>View on GitHub (pinned to c028a0c7dc)
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.
Example fix
// before settings.Modalities = 1; // after settings.Modalities = ChatResponseModalities.Text;
Defensive patterns
Strategy: type-guard
Validate before calling
static bool IsSupportedModalities(object? o) => o is ChatResponseModalities or string or IEnumerable<string> or JsonElement;
Type guard
static bool IsSupportedModalities(object? o) => o is ChatResponseModalities or string or IEnumerable<string> or JsonElement;
Try / catch
try { await client.GetChatCompletionAsync(...); }
catch (NotSupportedException ex) when (ex.Message.Contains("response modalities")) { settings.Modalities = ChatResponseModalities.Default; } Prevention
- Coerce dynamic values to enum/string/array/JsonElement(string|array).
- Ensure JSON deserializes Modalities as string or array, not object/number.
When it happens
Trigger: Setting Modalities to a non-supported type: an integer, a JObject/Dictionary, a JsonElement whose ValueKind is Object/Number/False, or a custom object.
Common situations: Deserializing settings where Modalities arrived as a JSON object or number; binding from dynamic config; cross-library interop that produces JsonNode instead of JsonElement.
Related errors
- The provided reasoning effort '{effortLevelObject.GetType()}
- The provided web search options '{executionSettings.WebSearc
- The provided response modalities '{modalityString}' is not s
- The provided response modalities '{responseModalitiesString}
- The provided audio options '{executionSettings.Audio?.GetTyp
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/09160ea59dbe0c9c.
Report an issue: GitHub.