BoundaryML/baml · error

unexpected type for mime type: %T

Error message

unexpected type for mime type: %T

What it means

After calling the runtime's `mime_type` method, the Go wrapper asserts the returned value is a Go string. If the FFI layer deserialized the result into any other Go type, this error is thrown with the actual %T. It indicates the Go client and native runtime disagree on the method's return type — usually an internal contract violation rather than user input.

Source

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

}

func (m *mediaHolder) pointer() int64 {
	return m.RawObject.Pointer()
}

func (m *mediaHolder) MimeType() (*string, error) {
	result, err := raw_objects.CallMethod(m, "mime_type", nil)
	if err != nil {
		return nil, fmt.Errorf("failed to get mime type: %w", err)
	}

	if result == nil {
		return nil, nil
	}

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

	return &as_mime_type, nil
}

func (m *mediaHolder) IsUrl() (bool, error) {
	result, err := raw_objects.CallMethod(m, "is_url", nil)
	if err != nil {
		return false, fmt.Errorf("failed to get is url: %w", err)
	}

	return result.(bool), nil
}

func (m *mediaHolder) IsBase64() (bool, error) {
	result, err := raw_objects.CallMethod(m, "is_base64", nil)
	if err != nil {
		return false, fmt.Errorf("failed to get is base64: %w", err)

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Pin matching versions of the baml Go module and baml-cli runtime
  2. Update the baml Go dependency to the latest release
  3. Report the %T value shown in the message to the BAML maintainers if versions match

Example fix

// before (mismatched versions)
require github.com/boundaryml/baml v0.55.0
// after (aligned)
go get github.com/boundaryml/baml@latest && baml-cli --version # ensure runtime matches module
Defensive patterns

Strategy: try-catch

Try / catch

mime, err := media.MimeType()
if err != nil && strings.Contains(err.Error(), "unexpected type") {
    return fmt.Errorf("client/runtime version mismatch: %w", err)
}

Prevention

When it happens

Trigger: Calling MimeType() when raw_objects.CallMethod returns a non-nil, non-string value (e.g. []byte, int) due to a serde/FFI type mismatch between the Go client and the Rust runtime.

Common situations: Mixed versions of the baml Go module and native library; a runtime change to the mime_type return type not yet reflected in the installed Go client.

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/e72ae2682024e9f0. Report an issue: GitHub.