BoundaryML/baml · error

unexpected type for clear result: %T

Error message

unexpected type for clear result: %T

What it means

Go type-assertion failure in the collector's Clear method: the bridge returned the clear result, but it is not an int64 (the %T names the actual type). The runtime and Go bindings disagree on the return shape of 'clear' — typically a version mismatch between the baml runtime and the generated Go library.

Source

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

	}

	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 against the matching BAML runtime so the return type is int64.
  2. Convert defensively in the client if a custom runtime returns another numeric type.
  3. Report upstream with the %T value if versions match.

Example fix

// before
count, ok := result.(int64)
// after
count, ok := result.(int64)
if !ok {
	if f, isF := result.(float64); isF { count = int64(f) }
}
Defensive patterns

Strategy: type-guard

Validate before calling

if collector == nil { return errors.New("collector not initialized") }

Type guard

func toInt64(v any) (int64, bool) {
	switch n := v.(type) {
	case int64: return n, true
	case int: return int64(n), true
	case float64: return int64(n), true
	}
	return 0, false
}

Try / catch

count, err := collector.Clear()
if err != nil {
	if strings.Contains(err.Error(), "unexpected type") { /* numeric type skew between runtimes */ }
	return err
}

Prevention

When it happens

Trigger: collector.Clear() where CallMethod returns a non-int64 (e.g. int, uint64 from a differently-built runtime, or nil).

Common situations: Mixed Go/native versions where the runtime returns a different numeric width/type; runtime returning nil on clear.

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