BoundaryML/baml · error

unexpected type for as_url: %T

Error message

unexpected type for as_url: %T

What it means

After the `as_url` FFI call succeeds, the wrapper asserts the result is a Go string. A non-nil result of any other Go type triggers this error with %T showing the actual type. It signals a serde/FFI contract violation between the Go client and the Rust runtime, not bad user input.

Solutions

  1. Update the baml Go dependency and native runtime to the same release
  2. Rebuild/reinstall to clear stale cached binaries
  3. File an issue with BAML including the %T reported in the message if versions match
Defensive patterns

Strategy: try-catch

Try / catch

url, err := media.AsUrl()
if err != nil && strings.Contains(err.Error(), "unexpected type") {
    return fmt.Errorf("upgrade baml Go module/runtime to fix serde mismatch: %w", err)
}

Prevention

When it happens

Trigger: Calling AsUrl() when the deserialized FFI result is a non-string type (e.g. []byte) due to a mismatch between Go-side expectations and the runtime's actual return type.

Common situations: Installing a newer native runtime than the Go module (or vice versa); a runtime change to as_url's return type not yet reflected in the pinned 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/78a6b95d7d86766d. Report an issue: GitHub.

Appendix: source

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

		return false, fmt.Errorf("failed to get is base64: %w", err)
	}

	return result.(bool), nil
}

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

	if result == nil {
		return nil, nil
	}

	as_url, ok := result.(string)
	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)
	}

View on GitHub (pinned to bd85ce9dee)