Skip to documentation
Documentation navigation

Documentation navigation

Documentation / guides

TextBlock

Construct and serialize plain text content blocks.

developer

TextBlock is the smallest content value: one string wrapped in the sealed content.Block interface. It is used for prompts, assistant text, structured-output fragments, and accumulated text deltas.

API surface

type TextBlock struct {
	Text string
}

There is no constructor and no validation method. Use a non-nil pointer when placing the value in []content.Block; the pointer is the concrete discriminator.

FieldMeaningOwnership
TextThe complete text for this blockThe block stores the string value; strings are immutable

JSON boundary

MarshalBlock adds the discriminator while preserving the exported field name:

block := &content.TextBlock{Text: "hello"}
wire, err := content.MarshalBlock(block)
// wire is an object containing {"Text":"hello","type":"text"}.
restored, err := content.UnmarshalBlock(wire)
text := restored.(*content.TextBlock).Text

Do not add a Type field to the struct. The codec owns the wire tag and rejects an unknown tag with *content.UnknownBlockTypeError.

Proof

Related: Content blocks, Text deltas.

← back to documentation