microsoft/semantic-kernel · error · NotSupportedException

The provided web search options '{executionSettings.WebSearc

Error message

The provided web search options '{executionSettings.WebSearchOptions.GetType()}' is not supported.

What it means

Thrown by GetWebSearchOptions after exhausting the three accepted shapes for executionSettings.WebSearchOptions: a ChatWebSearchOptions instance, a JSON string, or a JsonElement. Any other CLR type cannot be turned into the underlying ChatWebSearchOptions model, so the type is reported.

Source

Thrown at dotnet/src/Connectors/Connectors.OpenAI/Core/ClientCore.ChatCompletion.cs:606

            return null;
        }

        if (executionSettings.WebSearchOptions is ChatWebSearchOptions webSearchOptions)
        {
            return webSearchOptions;
        }

        if (executionSettings.WebSearchOptions is string webSearchOptionsString)
        {
            return ModelReaderWriter.Read<ChatWebSearchOptions>(BinaryData.FromString(webSearchOptionsString));
        }

        if (executionSettings.WebSearchOptions is JsonElement webSearchOptionsElement)
        {
            return ModelReaderWriter.Read<ChatWebSearchOptions>(BinaryData.FromString(webSearchOptionsElement.GetRawText()));
        }

        throw new NotSupportedException($"The provided web search options '{executionSettings.WebSearchOptions.GetType()}' is not supported.");
    }

    /// <summary>
    /// Retrieves the response format based on the provided settings.
    /// </summary>
    /// <param name="executionSettings">Execution settings.</param>
    /// <returns>Chat response format</returns>
    protected static ChatResponseFormat? GetResponseFormat(OpenAIPromptExecutionSettings executionSettings)
    {
        switch (executionSettings.ResponseFormat)
        {
            case ChatResponseFormat formatObject:
                // If the response format is an OpenAI SDK ChatCompletionsResponseFormat, just pass it along.
                return formatObject;
            case string formatString:
                // If the response format is a string, map the ones we know about, and ignore the rest.
                switch (formatString)
                {

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Pass a ChatWebSearchOptions instance, or a JSON string that deserializes into one, or a JsonElement of the same shape.
  2. If you only have a dictionary, serialize it to a JSON string first: JsonSerializer.Serialize(dict).
  3. Avoid anonymous types; they are not one of the supported kinds.

Example fix

// before
settings.WebSearchOptions = new { search_context_size = "medium" };
// after
settings.WebSearchOptions = "{\"search_context_size\":\"medium\"}";
Defensive patterns

Strategy: type-guard

Validate before calling

object NormalizeWebSearchOptions(object? o) => o switch { ChatWebSearchOptions or string or JsonElement => o, IDictionary<string,object?> d => JsonSerializer.Serialize(d), _ => throw new ArgumentException("WebSearchOptions must be ChatWebSearchOptions, JSON string, or JsonElement") };

Type guard

static bool IsSupportedWebSearchOptions(object? o) => o is ChatWebSearchOptions or string or JsonElement;

Try / catch

try { await client.GetChatCompletionAsync(...); }
catch (NotSupportedException ex) when (ex.Message.Contains("web search options")) { settings.WebSearchOptions = null; }

Prevention

When it happens

Trigger: Assigning WebSearchOptions a Dictionary<string,object>, an anonymous object, a JsonNode, or a custom DTO instead of one of the three supported shapes. The connector then has no path to serialize it for the request.

Common situations: Hand-building settings from dynamic config; interop with System.Text.Json.Nodes; passing a partial/raw object from another library.

Related errors


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