microsoft/autogen · error · JsonException

Unknown content type

Error message

Unknown content type

What it means

AutoGen.Anthropic's ContentBaseConverter (a System.Text.Json polymorphic converter for ContentBase) throws JsonException('Unknown content type') when a content block's 'type' field is anything other than text, image, tool_use, or tool_result. This surfaces whenever the Anthropic API introduces a new block type the package doesn't know — most notably 'thinking' blocks from extended-thinking models and 'redacted_thinking'.

Source

Thrown at dotnet/src/AutoGen.Anthropic/Converters/ContentBaseConverter.cs:32

        using var doc = JsonDocument.ParseValue(ref reader);
        if (doc.RootElement.TryGetProperty("type", out JsonElement typeProperty) && !string.IsNullOrEmpty(typeProperty.GetString()))
        {
            string? type = typeProperty.GetString();
            var text = doc.RootElement.GetRawText();
            switch (type)
            {
                case "text":
                    return JsonSerializer.Deserialize<TextContent>(text, options) ?? throw new InvalidOperationException();
                case "image":
                    return JsonSerializer.Deserialize<ImageContent>(text, options) ?? throw new InvalidOperationException();
                case "tool_use":
                    return JsonSerializer.Deserialize<ToolUseContent>(text, options) ?? throw new InvalidOperationException();
                case "tool_result":
                    return JsonSerializer.Deserialize<ToolResultContent>(text, options) ?? throw new InvalidOperationException();
            }
        }

        throw new JsonException("Unknown content type");
    }

    public override void Write(Utf8JsonWriter writer, ContentBase value, JsonSerializerOptions options)
    {
        JsonSerializer.Serialize(writer, value, value.GetType(), options);
    }
}

View on GitHub (pinned to 027ecf0a37)

Solutions

  1. Update AutoGen.Anthropic to a version that registers the new content types (thinking blocks are handled in newer releases).
  2. As a workaround, filter unknown blocks from the history before resending (keep only text/tool_use/tool_result blocks).
  3. Disable extended thinking / beta features that emit unsupported block types if you cannot upgrade yet.
  4. If you control the DTOs, add a passthrough case for unknown types instead of throwing.

Example fix

// before: history replay includes thinking blocks -> JsonException("Unknown content type")

// after: strip blocks the converter cannot handle before sending history back
var safeHistory = history
    .Where(m => m.Content?.Type is "text" or "tool_use" or "tool_result")
    .ToList();
Defensive patterns

Strategy: type-guard

Validate before calling

var knownTypes = new HashSet<string> { "text", "image", "tool_use", "tool_result" };
var unknownBlocks = history.SelectMany(m => m.Content ?? []).Where(b => b?.Type is not null && !knownTypes.Contains(b.Type)).ToList();
if (unknownBlocks.Count > 0) history = history.Select(m => m with { Content = m.Content?.Where(b => knownTypes.Contains(b?.Type ?? "")).ToList() }).ToList();

Type guard

static bool IsKnownContentBlock(string? type) => type is "text" or "image" or "tool_use" or "tool_result";

Try / catch

try { await agent.SendAsync(history); } catch (JsonException ex) when (ex.Message == "Unknown content type") { history = FilterToKnownBlocks(history); await agent.SendAsync(history); }

Prevention

When it happens

Trigger: Sending a conversation history back to a claude model with extended thinking enabled (assistant turns contain 'thinking' blocks); API returns a new content type in a response or in the input echo; using a newer Anthropic model than the AutoGen.Anthropic package supports.

Common situations: Upgrading the model (e.g. to a thinking-enabled claude) without upgrading AutoGen.Anthropic; replaying multi-turn histories that include tool_use/tool_result plus newer block types; beta features enabled via the 'anthropic-beta' header that add block types.

Related errors


AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15). Data as JSON: /api/errors/d3b8cdccff39ef07. Report an issue: GitHub.