Repository navigation
Conversation
Bedrock inspects the bytes of an attached document rather than trusting the declared format. A Shift_JIS text file is detected as application/octet-stream and the request fails with ValidationException: Unsupported MIME type, even though the format is declared as csv or txt. Re-encoding the same content to UTF-8 makes it acceptable, so convert text documents that are not valid UTF-8 before sending them. - Only txt, csv, md and html are considered; binary formats are never re-encoded - Bytes that are already valid UTF-8 are returned untouched - Bytes that no candidate encoding decodes cleanly are left alone so Bedrock still reports the problem - No new dependency: Node's built-in TextDecoder handles shift_jis and euc-jp
This was referenced Aug 22, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of Changes
Attaching a Shift_JIS encoded text file fails with:
I measured where this comes from by calling
bedrock-runtime:Conversedirectly inap-northeast-1(jp.anthropic.claude-haiku-4-5-20251001-v1:0), sending the same CSV indifferent encodings and changing nothing else:
formatcsvcsvtxtcsvSo the rejection comes from Bedrock, and the declared
formatis ignored — Bedrocksniffs the bytes. This confirms what @kazuhitogo found in #1399 and what @toshikwa noted
in #1181.
The last row is the part I would like to raise: the same content goes through once it is
re-encoded, so this can be fixed rather than only reported.
In #1399 the plan was to surface a clearer "UTF-8 only" message. That is a real improvement
over the current error, but #1181 asks for CSV files to be accepted regardless of
encoding, and Shift_JIS is still what several Japanese SaaS products emit when you export
a file. Converting on the server removes the manual step entirely.
If you would rather keep the error-message approach, I am happy to close this and send
that instead — I wrote this partly to show that transcoding is viable and cheap.
What this PR does
Adds
convertTextDocumentToUtf8and applies it where the Converse document content blockis built:
txt,csv,mdandhtmlare considered; binary formats (pdf,doc,docx,xls,xlsx) are never re-encodedshift_jistheneuc-jpare tried with a strict decoder, and the decoded textis re-encoded as UTF-8
problem rather than us silently sending mojibake
No new dependency. Node's built-in
TextDecodersupportsshift_jisandeuc-jp.Compatibility: UTF-8 and ASCII content is byte-for-byte unchanged, and binary formats
are untouched. The only behavior change is that files which previously failed the API call
now succeed.
Out of scope: the Bedrock Agents path in
bedrockAgentApi.tsusesbyteContentwith adifferent validation path, and UTF-16 is not attempted because a strict UTF-16 decode
accepts almost any byte sequence and would misfire.
Verified end to end
Passing the real output of
convertTextDocumentToUtf8to Converse:Checklist
comment explaining the Bedrock behavior)
npm run cdk:test— 49 tests / 15 snapshots passed, no snapshot differencesAlso run:
npm -w packages/cdk test -- textEncoding— 10 passednpm run web:test— 278 passednpm -w packages/cdk run lint(--max-warnings 0) andprettier --checkcleanRelated Issues