{"record":{"id":"3c74b2fc9a58e5c2","repo":"microsoft/semantic-kernel","slug":"unsupported-function-choice-config-choice","errorCode":null,"errorMessage":"Unsupported function choice '{config.Choice}'.","messagePattern":"Unsupported function choice '(.+?)'\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Connectors/Connectors.OpenAI/Core/ClientCore.ChatCompletion.cs","lineNumber":1349,"sourceCode":"        bool autoInvoke = config?.AutoInvoke ?? false;\n\n        if (config?.Functions is { Count: > 0 } functions)\n        {\n            if (config.Choice == FunctionChoice.Auto)\n            {\n                toolChoice = ChatToolChoice.CreateAutoChoice();\n            }\n            else if (config.Choice == FunctionChoice.Required)\n            {\n                toolChoice = ChatToolChoice.CreateRequiredChoice();\n            }\n            else if (config.Choice == FunctionChoice.None)\n            {\n                toolChoice = ChatToolChoice.CreateNoneChoice();\n            }\n            else\n            {\n                throw new NotSupportedException($\"Unsupported function choice '{config.Choice}'.\");\n            }\n\n            tools = [];\n\n            foreach (var function in functions)\n            {\n                tools.Add(function.Metadata.ToOpenAIFunction().ToFunctionDefinition(config?.Options?.AllowStrictSchemaAdherence ?? false));\n            }\n        }\n\n        return new(tools, toolChoice, autoInvoke, config?.Options);\n    }\n\n    /// <summary>\n    /// Processes non-function tool calls.\n    /// </summary>\n    /// <param name=\"toolCalls\">All tool calls requested by AI model.</param>\n    /// <param name=\"chatHistory\">The chat history.</param>","sourceCodeStart":1331,"sourceCodeEnd":1367,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/src/Connectors/Connectors.OpenAI/Core/ClientCore.ChatCompletion.cs#L1331-L1367","documentation":"Thrown in the tool-choice branch of ConfigureFunctionCalling. After mapping FunctionChoice.Auto/Required/None to the corresponding ChatToolChoice, the else branch catches any FunctionChoice enum value not handled (e.g. a future member or an invalid integer cast to FunctionChoice). The unsupported value is reported.","triggerScenarios":"config.Choice is a FunctionChoice value other than Auto, Required, or None — for example a newly added enum member not yet mapped by this connector build, or an integer cast like (FunctionChoice)99.","commonSituations":"Version skew between the FunctionChoice enum source and the connector; reflection/deserialization forcing an out-of-range enum value.","solutions":["Use FunctionChoice.Auto, Required, or None only.","If a new FunctionChoice member is needed, upgrade Connectors.OpenAI to a version that maps it.","Do not cast arbitrary integers to FunctionChoice."],"exampleFix":"// before\nvar cfg = new FunctionChoiceBehaviorConfig { Choice = (FunctionChoice)42 };\n// after\nvar cfg = new FunctionChoiceBehaviorConfig { Choice = FunctionChoice.Auto };","handlingStrategy":"validation","validationCode":"static readonly HashSet<FunctionChoice> ValidChoices = new() { FunctionChoice.Auto, FunctionChoice.Required, FunctionChoice.None };\nstatic void EnsureChoice(FunctionChoice c) { if (!ValidChoices.Contains(c)) throw new ArgumentException($\"FunctionChoice {c} not mapped\"); }","typeGuard":"static bool IsValidFunctionChoice(FunctionChoice c) => ValidChoices.Contains(c);","tryCatchPattern":"try { await client.GetChatCompletionAsync(...); }\ncatch (NotSupportedException ex) when (ex.Message.Contains(\"function choice\")) { /* fall back to FunctionChoice.Auto and retry */ }","preventionTips":["Use only Auto/Required/None.","Never cast arbitrary integers to FunctionChoice."],"tags":["openai","function-calling","tool-choice","enum-mapping"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}