BoundaryML/baml · error

unexpected type for log by id: %T

Error message

unexpected type for log by id: %T

What it means

Go type-assertion failure in the collector's Id method: the raw-objects bridge returned a value for the log lookup, but it is not a FunctionLog as Go expects (the %T shows the actual concrete type). This indicates a protocol mismatch between the Go bindings and the runtime version that answered the call.

Source

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

	log, ok := result.(FunctionLog)
	if !ok {
		return nil, fmt.Errorf("unexpected type for last log: %T %v", result, result)
	}

	return log, nil
}

func (c *collector) Id(functionId string) (FunctionLog, error) {
	result, err := raw_objects.CallMethod(c, "id", map[string]any{
		"id": functionId,
	})
	if err != nil {
		return nil, fmt.Errorf("failed to get log by id: %w", err)
	}

	log, ok := result.(FunctionLog)
	if !ok {
		return nil, fmt.Errorf("unexpected type for log by id: %T", result)
	}

	return log, nil
}

func (c *collector) Clear() (int64, error) {
	result, err := raw_objects.CallMethod(c, "clear", nil)
	if err != nil {
		return 0, fmt.Errorf("failed to clear: %w", err)
	}

	count, ok := result.(int64)
	if !ok {
		return 0, fmt.Errorf("unexpected type for clear result: %T", result)
	}

	return count, nil
}

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Rebuild with matching Go client and native runtime versions.
  2. Inspect the %T in the message for the leaked type.
  3. Report upstream if it persists on matched versions.

Example fix

// before
log, _ := collector.Id(fnId)
// after
log, err := collector.Id(fnId)
if err != nil {
	return err
}
var _ baml.FunctionLog = log // compile-time sanity
Defensive patterns

Strategy: type-guard

Validate before calling

if functionId == "" { return errors.New("functionId required") }

Type guard

func logById(c baml.Collector, id string) (baml.FunctionLog, bool) {
	l, err := c.Id(id)
	if err != nil { return nil, false }
	return l, true
}

Try / catch

log, err := collector.Id(functionId)
if err != nil {
	if strings.Contains(err.Error(), "unexpected type") { /* internal bug / version skew */ }
	return err
}

Prevention

When it happens

Trigger: collector.Id(...) where the native runtime returns a non-FunctionLog raw object for the given id — wrong object kind registered, or Go/native version mismatch.

Common situations: Version skew between Go bindings and native BAML runtime; runtime bug mapping the resolved object to the wrong Go adapter.

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