{"record":{"id":"470ef0387ce96949","repo":"microsoft/semantic-kernel","slug":"the-provided-web-search-options-executionsetting","errorCode":null,"errorMessage":"The provided web search options '{executionSettings.WebSearchOptions.GetType()}' is not supported.","messagePattern":"The provided web search options '(.+?)' is not supported\\.","errorType":"validation","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Connectors/Connectors.OpenAI/Core/ClientCore.ChatCompletion.cs","lineNumber":606,"sourceCode":"            return null;\n        }\n\n        if (executionSettings.WebSearchOptions is ChatWebSearchOptions webSearchOptions)\n        {\n            return webSearchOptions;\n        }\n\n        if (executionSettings.WebSearchOptions is string webSearchOptionsString)\n        {\n            return ModelReaderWriter.Read<ChatWebSearchOptions>(BinaryData.FromString(webSearchOptionsString));\n        }\n\n        if (executionSettings.WebSearchOptions is JsonElement webSearchOptionsElement)\n        {\n            return ModelReaderWriter.Read<ChatWebSearchOptions>(BinaryData.FromString(webSearchOptionsElement.GetRawText()));\n        }\n\n        throw new NotSupportedException($\"The provided web search options '{executionSettings.WebSearchOptions.GetType()}' is not supported.\");\n    }\n\n    /// <summary>\n    /// Retrieves the response format based on the provided settings.\n    /// </summary>\n    /// <param name=\"executionSettings\">Execution settings.</param>\n    /// <returns>Chat response format</returns>\n    protected static ChatResponseFormat? GetResponseFormat(OpenAIPromptExecutionSettings executionSettings)\n    {\n        switch (executionSettings.ResponseFormat)\n        {\n            case ChatResponseFormat formatObject:\n                // If the response format is an OpenAI SDK ChatCompletionsResponseFormat, just pass it along.\n                return formatObject;\n            case string formatString:\n                // If the response format is a string, map the ones we know about, and ignore the rest.\n                switch (formatString)\n                {","sourceCodeStart":588,"sourceCodeEnd":624,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/src/Connectors/Connectors.OpenAI/Core/ClientCore.ChatCompletion.cs#L588-L624","documentation":"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.","triggerScenarios":"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.","commonSituations":"Hand-building settings from dynamic config; interop with System.Text.Json.Nodes; passing a partial/raw object from another library.","solutions":["Pass a ChatWebSearchOptions instance, or a JSON string that deserializes into one, or a JsonElement of the same shape.","If you only have a dictionary, serialize it to a JSON string first: JsonSerializer.Serialize(dict).","Avoid anonymous types; they are not one of the supported kinds."],"exampleFix":"// before\nsettings.WebSearchOptions = new { search_context_size = \"medium\" };\n// after\nsettings.WebSearchOptions = \"{\\\"search_context_size\\\":\\\"medium\\\"}\";","handlingStrategy":"type-guard","validationCode":"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\") };","typeGuard":"static bool IsSupportedWebSearchOptions(object? o) => o is ChatWebSearchOptions or string or JsonElement;","tryCatchPattern":"try { await client.GetChatCompletionAsync(...); }\ncatch (NotSupportedException ex) when (ex.Message.Contains(\"web search options\")) { settings.WebSearchOptions = null; }","preventionTips":["Prefer ChatWebSearchOptions instances over dynamic objects.","Serialize dictionaries to JSON strings before assigning."],"tags":["openai","web-search","chat-completion","type-coercion"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}