{"record":{"id":"8e77433ae159fa0b","repo":"microsoft/semantic-kernel","slug":"failed-to-parse-the-provided-audio-options-from-st","errorCode":null,"errorMessage":"Failed to parse the provided audio options from string. Ensure the string is valid JSON that matches ChatAudioOptions format.","messagePattern":"Failed to parse the provided audio options from string\\. Ensure the string is valid JSON that matches ChatAudioOptions format\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Connectors/Connectors.AzureOpenAI/Core/AzureClientCore.ChatCompletion.cs","lineNumber":260,"sourceCode":"            catch (Exception ex)\n            {\n                throw new NotSupportedException(\"Failed to parse the provided audio options from JSON. Ensure the JSON structure matches ChatAudioOptions format.\", ex);\n            }\n        }\n\n        if (executionSettings.Audio is string audioOptionsString)\n        {\n            try\n            {\n                var result = ModelReaderWriter.Read<ChatAudioOptions>(BinaryData.FromString(audioOptionsString));\n                if (result != null)\n                {\n                    return result;\n                }\n            }\n            catch (Exception ex)\n            {\n                throw new NotSupportedException(\"Failed to parse the provided audio options from string. Ensure the string is valid JSON that matches ChatAudioOptions format.\", ex);\n            }\n        }\n\n        throw new NotSupportedException($\"The provided audio options '{executionSettings.Audio?.GetType()}' is not supported.\");\n    }\n}\n","sourceCodeStart":242,"sourceCodeEnd":267,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/src/Connectors/Connectors.AzureOpenAI/Core/AzureClientCore.ChatCompletion.cs#L242-L267","documentation":"Thrown inside GetAudioOptions when executionSettings.Audio is a string and ModelReaderWriter.Read<ChatAudioOptions> fails to parse it as valid JSON matching the ChatAudioOptions format (throws or returns null). This path is reached only when Audio is a C# string (not a JsonElement).","triggerScenarios":"Setting executionSettings.Audio = \"{\\\"voice\\\":\\\"\\\"}\" or any string that is either not valid JSON or does not conform to ChatAudioOptions. Common when the audio value is read from a flat config string rather than structured JSON.","commonSituations":"Loading a serialized audio JSON string from environment/config. Passing a malformed or partial JSON string. Schema mismatch with the Azure SDK ChatAudioOptions definition.","solutions":["Prefer constructing ChatAudioOptions directly rather than round-tripping through a JSON string.","If a JSON string is required, ensure it is valid JSON with the correct ChatAudioOptions field names and values.","Catch NotSupportedException and inspect ex.InnerException for the parse failure detail.","Validate the string parses as JSON before assigning to Audio."],"exampleFix":"// before\nsettings.Audio = \"{\\\"voice\\\":\\\"\\\"}\"; // invalid ChatAudioOptions\n// throws: Failed to parse the provided audio options from string...\n\n// after\n#pragma warning disable AOAI001\nsettings.Audio = new ChatAudioOptions(ChatAudioVoice.Alloy, ChatAudioFormat.Pcm16);\n#pragma warning restore AOAI001","handlingStrategy":"validation","validationCode":"static bool IsValidAudioJsonString(string s)\n{\n    try { using var doc = JsonDocument.Parse(s); return ModelReaderWriter.Read<ChatAudioOptions>(BinaryData.FromString(s)) is not null; }\n    catch { return false; }\n}","typeGuard":"bool IsParsableAudioString(string s)\n{\n    try { return ModelReaderWriter.Read<ChatAudioOptions>(BinaryData.FromString(s)) is not null; }\n    catch { return false; }\n}","tryCatchPattern":"try { /* kernel call */ }\ncatch (NotSupportedException ex) when (ex.Message.Contains(\"audio options from string\"))\n{ throw new ConfigurationException(\"Audio string must be valid JSON matching ChatAudioOptions.\", ex.InnerException); }","preventionTips":["Prefer constructing ChatAudioOptions directly over round-tripping a JSON string.","Validate the string parses to JSON and binds to ChatAudioOptions before assigning.","Inspect the inner parse exception for the precise schema problem."],"tags":["azure-openai","execution-settings","audio","json","configuration","csharp"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}