Skip to content

Conversation

@revmischa
Copy link

Summary

  • Fixes TypeError: Object of type ContentReasoning is not JSON serializable when deserializing eval logs containing extended thinking/reasoning content

Root Cause

The _wrap validator in ChatMessageBase creates a cache key using json.dumps(data). However, ChatMessageAssistant.extract_reasoning (a mode="before" validator) may create ContentReasoning and ContentText Pydantic model objects in the data dict before _wrap runs. Standard json.dumps cannot serialize Pydantic models.

Fix

Added a custom JSON encoder _PydanticJSONEncoder that handles Pydantic BaseModel objects by calling model_dump(mode="json").

Test plan

  • Verified fix with test case simulating ContentReasoning deserialization
  • Tested with eval logs containing <think> blocks

🤖 Generated with Claude Code

The `_wrap` validator in `ChatMessageBase` creates a cache key by calling
`json.dumps(data)`. However, `ChatMessageAssistant.extract_reasoning` (a
mode="before" validator) may create `ContentReasoning` and `ContentText`
Pydantic model objects in the data dict before `_wrap` runs. Standard
`json.dumps` cannot serialize Pydantic models, causing a TypeError.

This adds a custom JSON encoder that handles Pydantic BaseModel objects
by calling `model_dump(mode="json")` on them.

Fixes deserialization of eval logs containing ContentReasoning objects.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@revmischa revmischa closed this Jan 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants