Skip to content

Commit 54fca66

Browse files
PierrunoYTclaude
andcommitted
fix(bedrock): use a non-blank placeholder for a turn that held only filtered reasoning
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
1 parent 240de8b commit 54fca66

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

‎src/api/transform/__tests__/bedrock-converse-format.spec.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// npx vitest run src/api/transform/__tests__/bedrock-converse-format.spec.ts
22

3-
import { convertToBedrockConverseMessages } from "../bedrock-converse-format"
3+
import { convertToBedrockConverseMessages, REASONING_ONLY_PLACEHOLDER } from "../bedrock-converse-format"
44
import { Anthropic } from "@anthropic-ai/sdk"
55
import { ContentBlock, ToolResultContentBlock } from "@aws-sdk/client-bedrock-runtime"
66
import { OPENAI_CALL_ID_MAX_LENGTH } from "../../../utils/tool-id"
@@ -83,8 +83,10 @@ describe("convertToBedrockConverseMessages", () => {
8383

8484
expect(convertToBedrockConverseMessages(messages)).toStrictEqual([
8585
{ role: "assistant", content: [{ text: "Reading the file." }] },
86-
{ role: "assistant", content: [{ text: "" }] },
86+
// Bedrock rejects blank text blocks, so a reasoning-only turn keeps a non-blank placeholder.
87+
{ role: "assistant", content: [{ text: REASONING_ONLY_PLACEHOLDER }] },
8788
])
89+
expect(REASONING_ONLY_PLACEHOLDER.trim()).not.toBe("")
8890
})
8991

9092
it("drops signatures issued by another provider when converting thinking blocks", () => {

‎src/api/transform/bedrock-converse-format.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import { Anthropic } from "@anthropic-ai/sdk"
22
import { ConversationRole, Message, ContentBlock } from "@aws-sdk/client-bedrock-runtime"
33
import { sanitizeOpenAiCallId } from "../../utils/tool-id"
44

5+
/** Stand-in text for a turn whose only content was filtered reasoning (Bedrock rejects blank text). */
6+
export const REASONING_ONLY_PLACEHOLDER = "[Reasoning omitted]"
7+
58
interface BedrockMessageContent {
69
type: "text" | "image" | "video" | "tool_use" | "tool_result" | "reasoning" | "thinking"
710
text?: string
@@ -246,10 +249,11 @@ export function convertToBedrockConverseMessages(
246249

247250
return {
248251
role,
249-
// Bedrock rejects an empty content array; a reasoning-only turn becomes empty text.
252+
// Bedrock rejects an empty content array and blank text blocks, so a turn that held only
253+
// reasoning keeps its place in the conversation with a short non-blank placeholder.
250254
content:
251255
content.length === 0 && anthropicMessage.content.length > 0
252-
? ([{ text: "" }] as ContentBlock[])
256+
? ([{ text: REASONING_ONLY_PLACEHOLDER }] as ContentBlock[])
253257
: content,
254258
}
255259
})

0 commit comments

Comments
 (0)