{"record":{"id":"e20409867392a66a","repo":"microsoft/semantic-kernel","slug":"the-provided-response-format-type-responseformat","errorCode":null,"errorMessage":"The provided response format type '{responseFormat.GetType()}' is not supported.","messagePattern":"The provided response format type '(.+?)' is not supported\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Connectors/Connectors.OpenAI/Core/ClientCore.TextToImage.cs","lineNumber":169,"sourceCode":"            return null;\n        }\n\n        if (responseFormat is GeneratedImageFormat format)\n        {\n            return format;\n        }\n\n        if (responseFormat is string formatString)\n        {\n            return formatString.ToUpperInvariant() switch\n            {\n                \"URI\" or \"URL\" => GeneratedImageFormat.Uri,\n                \"BYTES\" or \"B64_JSON\" => GeneratedImageFormat.Bytes,\n                _ => throw new NotSupportedException($\"The provided response format '{formatString}' is not supported.\")\n            };\n        }\n\n        throw new NotSupportedException($\"The provided response format type '{responseFormat.GetType()}' is not supported.\");\n    }\n}\n","sourceCodeStart":151,"sourceCodeEnd":172,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/src/Connectors/Connectors.OpenAI/Core/ClientCore.TextToImage.cs#L151-L172","documentation":"The response format object is expected to be either a GeneratedImageFormat enum or a string. If it is non-null and neither of those types (e.g. an int, a custom class, a JObject), NotSupportedException is thrown with the actual type name. This is a type-level guard before any string matching occurs.","triggerScenarios":"Passing a response format from configuration or a dynamic source that deserializes to an unexpected type — e.g. a JsonElement, an anonymous object, an enum that is not GeneratedImageFormat, or a numeric value.","commonSituations":"Binding execution settings from JSON/IConfiguration where the deserializer produces a JsonElement or a different enum. Passing a loosely-typed 'object' from configuration parsing without converting it first. Version mismatch where a renamed enum type no longer matches.","solutions":["Convert the value to a string or GeneratedImageFormat enum before assignment.","If loading from configuration, explicitly type the property as string and let the connector parse it.","Use the strongly-typed GeneratedImageFormat enum to prevent type ambiguity."],"exampleFix":"// before — raw config object, type unknown\nsettings.ResponseFormat = configSection[\"responseFormat\"];\n\n// after — coerce to string or enum\nsettings.ResponseFormat = configSection[\"responseFormat\"]?.ToString();\n// or\nsettings.ResponseFormat = GeneratedImageFormat.Bytes;","handlingStrategy":"type-guard","validationCode":"object? CoerceResponseFormat(object? raw)\n{\n    return raw switch\n    {\n        null => null,\n        GeneratedImageFormat f => f,\n        string s => s,\n        System.Text.Json.JsonElement je => je.GetString(),\n        _ => throw new ArgumentException($\"ResponseFormat must be string or GeneratedImageFormat, got {raw.GetType().Name}\")\n    };\n}","typeGuard":"bool IsValidResponseFormat(object? value) =>\n    value is null || value is GeneratedImageFormat || value is string;","tryCatchPattern":"try { await imageService.GetTextToImageAsync(prompt, settings); }\ncatch (NotSupportedException ex) when (ex.Message.Contains(\"response format type\"))\n{\n    settings.ResponseFormat = GeneratedImageFormat.Uri;\n    await imageService.GetTextToImageAsync(prompt, settings);\n}","preventionTips":["Always type execution-settings properties as string or GeneratedImageFormat, never object.","When binding from JSON configuration, explicitly convert JsonElement to string."],"tags":["text-to-image","response-format","type-validation","configuration"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}