Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@kevmyung
Copy link

Summary

Fixes the TypeError: Object of type bytes is not JSON serializable error in message_to_payload when messages contain binary data (e.g., images from tool results).

Problem

The _filter_empty_text function was applied to session_message.message (which contains raw bytes) before to_dict() was called. The filtered message (with raw bytes) then overwrote the encoded version, causing json.dumps() to fail.

Solution

Reorder operations to:

  1. Call to_dict() first (encodes bytes to base64)
  2. Apply _filter_empty_text to the encoded message

Testing

Verified with test script that:

  • v1.1.1: PASS (no _filter_empty_text)
  • v1.1.2: FAIL (message_to_payload with image bytes)
  • v1.1.2 + this fix: PASS

Fixes #198

The _filter_empty_text function was applied to the raw session_message.message
which contains unencoded bytes. This caused json.dumps() to fail with
'Object of type bytes is not JSON serializable' when messages contained
image data (e.g., tool results with screenshots or diagrams).

The fix reorders the operations to call to_dict() first (which encodes
bytes to base64 via encode_bytes_values()), then applies _filter_empty_text
to the already-encoded message.

Fixes aws#198
@kevmyung kevmyung deployed to manual-approval December 31, 2025 08:30 — with GitHub Actions Active
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.

Bug: message_to_payload fails with 'Object of type bytes is not JSON serializable' when message contains image bytes

1 participant