Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions core/providers/bedrock.go
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,12 @@ func (provider *BedrockProvider) prepareChatCompletionMessages(messages []schema
})
} else if msg.Content.ContentBlocks != nil {
for _, block := range *msg.Content.ContentBlocks {
if block.Text != nil {
content = append(content, BedrockAnthropicTextMessage{
Type: "text",
Text: *block.Text,
})
}
Comment on lines +522 to +527
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Guard against empty or whitespace-only text blocks
While the new nil check prevents pointer dereferences, empty strings still generate no-op messages. Filter out blocks with empty or whitespace-only text to keep the payload clean.

Apply this diff:

@@ -521,7 +521,8 @@
-                       if block.Text != nil {
+                       if block.Text != nil && strings.TrimSpace(*block.Text) != "" {
                            content = append(content, BedrockAnthropicTextMessage{
                                Type: "text",
                                Text: *block.Text,
                            })
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if block.Text != nil {
content = append(content, BedrockAnthropicTextMessage{
Type: "text",
Text: *block.Text,
})
}
if block.Text != nil && strings.TrimSpace(*block.Text) != "" {
content = append(content, BedrockAnthropicTextMessage{
Type: "text",
Text: *block.Text,
})
}
🤖 Prompt for AI Agents
In core/providers/bedrock.go around lines 522 to 527, the code appends text
messages even if the text is empty or contains only whitespace. To fix this, add
a check to ensure block.Text is not nil and that the dereferenced string is not
empty or whitespace-only before appending the message. Use a string trimming
function to verify the text content is meaningful and skip appending if it is
empty after trimming.

if block.ImageURL != nil {
sanitizedURL, _ := SanitizeImageURL(block.ImageURL.URL)
urlTypeInfo := ExtractURLTypeInfo(sanitizedURL)
Expand Down