BoundaryML/baml · error

unexpected type for name: %T

Error message

unexpected type for name: %T

What it means

After Collector.Name() retrieves a value from the runtime, it asserts the result is a Go string. If the FFI decoder returns any other type (int pointer, raw object, nil, etc.), this error is thrown. The call reached the runtime fine; the returned payload just did not decode to the expected string, meaning the runtime/bindings contract was broken.

Source

Thrown at engine/language_client_go/pkg/rawobjects_collector.go:49

	}

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

	return usage, nil
}

func (c *collector) Name() (string, error) {
	result, err := raw_objects.CallMethod(c, "name", nil)
	if err != nil {
		return "", fmt.Errorf("failed to get name: %w", err)
	}

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

	return name, nil
}

func (c *collector) Logs() ([]FunctionLog, error) {
	result, err := raw_objects.CallMethod(c, "logs", nil)
	if err != nil {
		return nil, fmt.Errorf("failed to get logs: %w", err)
	}

	logs, ok := result.([]raw_objects.RawPointer)
	if !ok {
		return nil, fmt.Errorf("unexpected type for logs: %T", result)
	}

	functionLogs := make([]FunctionLog, len(logs))
	for i, log := range logs {

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Align the Go module and BAML runtime versions; reinstall both together.
  2. Recreate the collector as a named collector (b.Collector("my-name", ...)) and retry.
  3. Log the %T value from the error and search BAML issues for that type to see if it's a known decoder bug.
  4. If persistent, file a bug with the reproduction and the printed type.

Example fix

// before
name, err := collector.Name()
// after
name, err := collector.Name()
if err != nil {
    return "", fmt.Errorf("unexpected name payload from runtime: %w", err)
}
Defensive patterns

Strategy: type-guard

Validate before calling

// Validate collector identity before reading:
// if collector == nil { return errors.New("nil collector") }

Type guard

func isString(result any) bool {
    s, ok := result.(string)
    return ok && s != ""
}

Try / catch

name, err := collector.Name()
if err != nil {
    if strings.Contains(err.Error(), "unexpected type for name") {
        return "", fmt.Errorf("runtime returned non-string name (version mismatch?): %w", err)
    }
    return "", err
}

Prevention

When it happens

Trigger: Calling collector.Name() when the runtime's `name` method returns a non-string value — a wrongly-typed decoded object, nil, or a numeric handle due to a decoder type-tag mismatch.

Common situations: Version drift between the Go client and native runtime; a collector object created by a mismatched runtime; an anonymous collector whose name resolves to a non-string placeholder.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


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