Skip to content

anthropic.ContentBlockSourceContentUnionParam does not seem to marshal correctly #229

@paddyjok

Description

@paddyjok

When trying to use the SDK to add a Custom Content Document eg:

{
    "type": "document",
    "source": {
        "type": "content",
        "content": [
            {"type": "text", "text": "The grass is green."},
            {"type": "text", "text": "The sky is blue."}
        ]
    },
    "title": "Document Title", # optional
    "context": "Context about the document that will not be cited from", # optional
    "citations": {"enabled": True}
}

using this code:

        // Create content blocks for the structured document
	contentBlocks := []anthropic.ContentBlockSourceContentUnionParam{
		{
			OfString: param.NewOpt("The grass is green."),
		},
		{
			OfString: param.NewOpt("The sky is blue."),
		},
	}

	// Create the document with content source (structured content for citations)
	documentBlock := anthropic.NewDocumentBlock(anthropic.ContentBlockSourceParam{
		Content: anthropic.ContentBlockSourceContentUnionParam{
			OfContentBlockSourceContent: contentBlocks,
		},
	})

I get the following error from the API:

{"type":"error","error":{"type":"invalid_request_error","message":"messages.0.content.0.document.source.content.content.0: Input should be a valid dictionary or object to extract fields from"},"request_id":"req_011CSoQmM3LxgiryWij2SwUt"}

Looking at the json that was marshaled, we get:

 {
	                   "source": {
	                        "content": [
	                            "The grass is green.",  <----- these should be objects with type and text keys  {"type": "text", "text": "The grass is green."}
	                            "The sky is blue."
	                         ],
	                         "type": "content"
	                     },
	                     "context": "This is a trustworthy document.",
	                    "title": "My Document",
	                    "citations": {
	                         "enabled": true
	                     },
	                     "type": "document"
	                 },

It looks like the SDK is not marshaling these correctly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions