Skip to content

fix: anthropic thinking block schema#1466

Merged
looplj merged 1 commit into
unstablefrom
dev-tmp
Apr 24, 2026
Merged

fix: anthropic thinking block schema#1466
looplj merged 1 commit into
unstablefrom
dev-tmp

Conversation

@looplj

@looplj looplj commented Apr 23, 2026

Copy link
Copy Markdown
Owner

@greptile-apps greptile-apps Bot left a comment

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.

looplj has reached the 50-review limit for trial accounts. To continue receiving code reviews, upgrade your plan.

@gemini-code-assist gemini-code-assist Bot left a comment

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.

Code Review

This pull request introduces custom JSON marshaling for MessageContentBlock and StreamDelta within the Anthropic transformer to handle thinking blocks. The implementation ensures that the signature field is included in the output even when empty. Review feedback suggests that the thinking field should also be explicitly included for consistency with the API schema and that the test suite should be expanded to include nil pointer scenarios to properly verify the custom marshaling behavior.

Comment on lines +347 to +357
if b.Type == "thinking" {
type thinkingBlock struct {
blockAlias
Signature string `json:"signature"`
}

return json.Marshal(thinkingBlock{
blockAlias: blockAlias(b),
Signature: lo.FromPtr(b.Signature),
})
}

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.

medium

For thinking content blocks, both the thinking and signature fields are typically required by the Anthropic API schema. While you've correctly forced the signature field to be present (even if empty), the thinking field should also be handled similarly to ensure it's not omitted when it's an empty string or nil.

Suggested change
if b.Type == "thinking" {
type thinkingBlock struct {
blockAlias
Signature string `json:"signature"`
}
return json.Marshal(thinkingBlock{
blockAlias: blockAlias(b),
Signature: lo.FromPtr(b.Signature),
})
}
if b.Type == "thinking" {
type thinkingBlock struct {
blockAlias
Thinking string "json:\"thinking\""
Signature string "json:\"signature\""
}
return json.Marshal(thinkingBlock{
blockAlias: blockAlias(b),
Thinking: lo.FromPtr(b.Thinking),
Signature: lo.FromPtr(b.Signature),
})
}

Comment on lines +11 to +19
func TestMessageContentBlockMarshalJSON_PreservesEmptyThinkingSignature(t *testing.T) {
data, err := json.Marshal(MessageContentBlock{
Type: "thinking",
Thinking: lo.ToPtr(""),
Signature: lo.ToPtr(""),
})
require.NoError(t, err)
require.JSONEq(t, `{"type":"thinking","thinking":"","signature":""}`, string(data))
}

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.

medium

The current test uses lo.ToPtr(""), which doesn't fully verify the custom MarshalJSON logic because a non-nil pointer to an empty string is already preserved by the default JSON marshaler (it's not considered an "empty value" for the pointer itself). To properly test that the custom marshaler forces these fields to be present even when they are uninitialized, you should add a test case where Thinking and Signature are nil.

@devin-ai-integration devin-ai-integration Bot left a comment

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.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 3 additional findings.

Open in Devin Review

@greptile-apps greptile-apps Bot left a comment

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.

looplj has reached the 50-review limit for trial accounts. To continue receiving code reviews, upgrade your plan.

@looplj looplj merged commit dc116c3 into unstable Apr 24, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant