Skip to content

fix(bedrock-kb-retrieval): preserve non-ASCII characters in tool output - #4372

Open
Baddala-Govardhan wants to merge 1 commit into
awslabs:mainfrom
Baddala-Govardhan:fix/bedrock-kb-retrieval-non-ascii
Open

fix(bedrock-kb-retrieval): preserve non-ASCII characters in tool output#4372
Baddala-Govardhan wants to merge 1 commit into
awslabs:mainfrom
Baddala-Govardhan:fix/bedrock-kb-retrieval-non-ascii

Conversation

@Baddala-Govardhan

@Baddala-Govardhan Baddala-Govardhan commented Jul 29, 2026

Copy link
Copy Markdown

Fixes #3820

json.dumps() defaults to ensure_ascii=True, so any non-ASCII text in a
Knowledge Base (Japanese/Korean/Chinese, emoji, accented characters) was
coming back as \uXXXX escapes instead of the actual text. Besides being
unreadable, it also bloats token usage since each CJK char turns into a
6-char escape sequence.

Added ensure_ascii=False in the two places that serialize results
(server.py and knowledgebases/retrieval.py) since the transport is
UTF-8 anyway.

Added tests for both spots to make sure non-ASCII text round-trips without
getting escaped. Ran the full suite + pre-commit, all green.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of the project license.

QueryKnowledgeBases and ListKnowledgeBases serialized results with
json.dumps() using its default ensure_ascii=True, turning CJK text,
accented characters, and emoji into \uXXXX escape sequences instead
of readable text. This inflated token usage and made raw tool output
unreadable. Pass ensure_ascii=False at both serialization points
since the transport is already UTF-8.

Fixes awslabs#3820
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: To triage

Development

Successfully merging this pull request may close these issues.

bedrock-kb-retrieval: QueryKnowledgeBases/ListKnowledgeBases return non-ASCII (CJK, emoji) as \uXXXX escapes

1 participant