Skip to content

Conversation

@mhpenta
Copy link

@mhpenta mhpenta commented Aug 21, 2025

Problem

When using document blocks with custom content for citations, the SDK was not marshaling the content correctly. The API expects content blocks to be formatted as [{"type": "text", "text": "..."}], but the SDK was sending malformed JSON for string arrays.

Solution

Added custom MarshalJSON implementation for BetaContentBlockSourceContentUnionParam that detects when content blocks contain strings and transforms them into the proper text block format expected by the Anthropic API. (I implemented a similar feature in https://github.com/liushuangls/go-anthropic.)

Testing

  • Added unit tests to verify the JSON transformation logic
  • Added integration test to confirm the API accepts the properly formatted requests

This fix enables citations to work correctly with custom document content blocks.

@mhpenta mhpenta requested a review from a team as a code owner August 21, 2025 22:00
@mhpenta
Copy link
Author

mhpenta commented Sep 8, 2025

Has anyone reviewed this?

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