BoundaryML/baml · error

unexpected type for as_base64: %T

Error message

unexpected type for as_base64: %T

What it means

After the `as_base64` FFI call succeeds, the wrapper asserts the result is a Go string. Any non-nil result of another Go type raises this error with %T. This is an internal serde/FFI contract violation between the Go client and the Rust runtime — the installed components disagree on the method's return type.

Solutions

  1. go get github.com/boundaryml/baml@latest and reinstall the matching baml-cli runtime
  2. Verify versions with go list -m github.com/boundaryml/baml and baml-cli --version
  3. Report the %T from the message to BAML maintainers if versions are aligned
Defensive patterns

Strategy: try-catch

Try / catch

b64, err := media.AsBase64()
if err != nil && strings.Contains(err.Error(), "unexpected type") {
    return fmt.Errorf("baml serde mismatch, upgrade components: %w", err)
}

Prevention

When it happens

Trigger: Calling AsBase64() when raw_objects.CallMethod returns a deserialized value that is not a string (e.g. []byte) because of a Go/runtime type-encoding mismatch.

Common situations: Partial upgrade: new native library with an older pinned Go module (or the reverse); custom builds of the runtime with altered return types.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12). Data as JSON: /api/errors/511677f8eee657e6. Report an issue: GitHub.

Appendix: source

Thrown at engine/language_client_go/pkg/rawobjects_media.go:148

	if !ok {
		return nil, fmt.Errorf("unexpected type for as_url: %T", result)
	}

	return &as_url, nil
}
func (m *mediaHolder) AsBase64() (*string, error) {
	result, err := raw_objects.CallMethod(m, "as_base64", nil)
	if err != nil {
		return nil, fmt.Errorf("failed to get as base64: %w", err)
	}

	if result == nil {
		return nil, nil
	}

	as_base64, ok := result.(string)
	if !ok {
		return nil, fmt.Errorf("unexpected type for as_base64: %T", result)
	}

	return &as_base64, nil
}

func newMedia(ptr int64, rt unsafe.Pointer, mediaType MediaType) media {
	media := mediaHolder{raw_objects.FromPointer(ptr, rt), mediaType}
	switch mediaType {
	case MediaType_Image:
		return &imageHolder{media}
	case MediaType_Audio:
		return &audioHolder{media}
	case MediaType_PDF:
		return &pdfHolder{media}
	case MediaType_Video:
		return &videoHolder{media}
	default:
		panic(fmt.Sprintf("invalid media type: '%s'", mediaType))

View on GitHub (pinned to bd85ce9dee)