Skip to content

Python: Bedrock JSON content blocks escape non-ASCII characters to \uXXXX #6627

Description

@kimnamu

Summary

Thanks for Agent Framework and the Bedrock integration — it's been great to use.

When the Bedrock Converse API returns a structured json content block, BedrockChatClient serializes it to text with json.dumps(json_value). Because json.dumps defaults to ensure_ascii=True, any non-ASCII characters (CJK, emoji, accented Latin, etc.) are escaped to \uXXXX sequences and surface garbled to the user.

Location: python/packages/bedrock/agent_framework_bedrock/_chat_client.py, in _parse_message_contents:

if (json_value := block.get("json")) is not None:
    contents.append(Content.from_text(text=json.dumps(json_value), raw_representation=block))
    continue

Reproduction

A json content block carrying {"greeting": "你好世界", "emoji": "🎉"} is turned into the text:

{"greeting": "你好世界", "emoji": "🎉"}

instead of the readable:

{"greeting": "你好世界", "emoji": "🎉"}

Expected behavior

Non-ASCII characters should be preserved as-is, matching the rest of the codebase. The sibling OpenAI client uses ensure_ascii=False (python/packages/openai/agent_framework_openai/_chat_client.py), and 16+ call sites across the repo already pass ensure_ascii=False for user-facing / span serialization. This one line in the Bedrock client is the outlier. PR #3894 ("Python: Fix non-ascii chars in span attributes") fixed the same class of issue in observability.

Proposed fix

Add ensure_ascii=False to that single json.dumps call, with a regression test. I'd like to take this on — PR to follow.


This issue was prepared with the help of an AI agent (Claude Code); a human reviewed the reproduction and proposed fix before filing.

Metadata

Metadata

Labels

pythonUsage: [Issues, PRs], Target: PythonreproducedUsage: [Issues], Target: all issues that can be reproduced by the triage workflow

Type

Projects

Status
Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions