microsoft/semantic-kernel · error · NotSupportedException
The provided response format type '{responseFormat.GetType()
Error message
The provided response format type '{responseFormat.GetType()}' is not supported. What it means
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.
Source
Thrown at dotnet/src/Connectors/Connectors.OpenAI/Core/ClientCore.TextToImage.cs:169
return null;
}
if (responseFormat is GeneratedImageFormat format)
{
return format;
}
if (responseFormat is string formatString)
{
return formatString.ToUpperInvariant() switch
{
"URI" or "URL" => GeneratedImageFormat.Uri,
"BYTES" or "B64_JSON" => GeneratedImageFormat.Bytes,
_ => throw new NotSupportedException($"The provided response format '{formatString}' is not supported.")
};
}
throw new NotSupportedException($"The provided response format type '{responseFormat.GetType()}' is not supported.");
}
}
View on GitHub (pinned to c028a0c7dc)
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.
Example fix
// before — raw config object, type unknown settings.ResponseFormat = configSection["responseFormat"]; // after — coerce to string or enum settings.ResponseFormat = configSection["responseFormat"]?.ToString(); // or settings.ResponseFormat = GeneratedImageFormat.Bytes;
Defensive patterns
Strategy: type-guard
Validate before calling
object? CoerceResponseFormat(object? raw)
{
return raw switch
{
null => null,
GeneratedImageFormat f => f,
string s => s,
System.Text.Json.JsonElement je => je.GetString(),
_ => throw new ArgumentException($"ResponseFormat must be string or GeneratedImageFormat, got {raw.GetType().Name}")
};
} Type guard
bool IsValidResponseFormat(object? value) =>
value is null || value is GeneratedImageFormat || value is string; Try / catch
try { await imageService.GetTextToImageAsync(prompt, settings); }
catch (NotSupportedException ex) when (ex.Message.Contains("response format type"))
{
settings.ResponseFormat = GeneratedImageFormat.Uri;
await imageService.GetTextToImageAsync(prompt, settings);
} Prevention
- Always type execution-settings properties as string or GeneratedImageFormat, never object.
- When binding from JSON configuration, explicitly convert JsonElement to string.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- The provided response format '{formatString}' is not support
- If response_format has type 'json_schema', 'json_schema' mus
- Encountered unexpected response_format type: {resp_type}. Al
- response_format must be a dictionary, a subclass of BaseMode
- The OpenAI text to image model ID is required.
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/e20409867392a66a.
Report an issue: GitHub.