microsoft/autogen · error · JsonException
Unable to convert "{value}" to enum {typeToConvert}.
Error message
Unable to convert "{value}" to enum {typeToConvert}. What it means
JsonPropertyNameEnumConverter<T>.Read iterates the enum's fields and matches the incoming JSON string against each field's [JsonPropertyName] name. If no field's attribute name equals the string, conversion is impossible and this JsonException (echoing the value and enum type) is thrown.
Source
Thrown at dotnet/src/AutoGen.Mistral/Converters/JsonPropertyNameEnumConverter.cs:26
namespace AutoGen.Mistral;
internal sealed class JsonPropertyNameEnumConverter<T> : JsonConverter<T> where T : struct, Enum
{
public override T Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
string value = reader.GetString() ?? throw new JsonException("Value was null.");
foreach (var field in typeToConvert.GetFields())
{
var attribute = field.GetCustomAttribute<JsonPropertyNameAttribute>();
if (attribute?.Name == value)
{
return (T)Enum.Parse(typeToConvert, field.Name);
}
}
throw new JsonException($"Unable to convert \"{value}\" to enum {typeToConvert}.");
}
public override void Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options)
{
var field = value.GetType().GetField(value.ToString());
var attribute = field?.GetCustomAttribute<JsonPropertyNameAttribute>();
if (attribute != null)
{
writer.WriteStringValue(attribute.Name);
}
else
{
writer.WriteStringValue(value.ToString());
}
}
}
View on GitHub (pinned to 027ecf0a37)
Solutions
- Update AutoGen.Mistral (and Mistral SDK) to a version whose enums include the new value — the message tells you exactly which string is missing.
- If updating is blocked, add the missing [JsonPropertyName] member to a local fork of the enum.
- Capture the raw HTTP response to confirm which endpoint/field carried the unknown value before upgrading.
Example fix
// before (SDK enum)
public enum FinishReasonEnum { [JsonPropertyName("stop")] Stop, [JsonPropertyName("length")] Length }
// API returns "content_filter" -> JsonException
// after (add the member)
public enum FinishReasonEnum { [JsonPropertyName("stop")] Stop, [JsonPropertyName("length")] Length, [JsonPropertyName("content_filter")] ContentFilter } Defensive patterns
Strategy: try-catch
Try / catch
try { var response = JsonSerializer.Deserialize<ChatCompletionResponse>(json, options); } catch (JsonException ex) when (ex.Message.Contains("Unable to convert")) { /* capture value + upgrade SDK */ } Prevention
- Update AutoGen.Mistral promptly after Mistral API releases
- Monitor the exception message for the unknown enum string
- Pin tested API/model versions in production
When it happens
Trigger: The Mistral API returns an enum string the SDK does not know — e.g. a newly added finish reason, tool type, or model capability not present in the shipped enum fields of the AutoGen.Mistral version in use.
Common situations: Mistral ships a new finish_reason/tool variant after the package was released; using a preview/beta Mistral model with extended enums; typos in hand-crafted JSON fed to the client.
Related errors
- Value was null.
- Failed to deserialize response
- Failed to create gallery
- Invalid JSON response from server. Check if the MCP route is
- Invalid JSON response from server. Check if the MCP route is
AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15).
Data as JSON: /api/errors/08d1a32782c46c7d.
Report an issue: GitHub.