BoundaryML/baml · error

unexpected type for duration: %T

Error message

unexpected type for duration: %T

What it means

When the "duration_ms" FFI call returns a non-nil value, DurationMs() asserts it is a Go int64 before returning a pointer to it. A non-int64, non-nil result (e.g. float64 or uint64 from the bridge decoder) triggers this error. Like the start-time variant, this is a bridge-encoding contract violation rather than caller misuse.

Solutions

  1. Inspect %T in the error message to learn the actual returned Go type.
  2. Sync the baml Go module version with the native BAML runtime version so int64 encoding is restored.
  3. As a workaround, access duration via JSON/other accessors and convert the alternate numeric type yourself.
  4. Report an upstream decoding bug if versions match and the error persists.

Example fix

// before (strict assertion)
dur, err := timing.DurationMs()
if err != nil {
    return err
}
log.Println(*dur)

// after: degrade gracefully when the bridge type drifts
dur, err := timing.DurationMs()
if err != nil {
    log.Printf("duration type mismatch: %v", err)
    return nil
}
Defensive patterns

Strategy: type-guard

Type guard

func isInt64(v any) bool { _, ok := v.(int64); return ok }

Try / catch

dur, err := timing.DurationMs()
if err != nil {
    if strings.Contains(err.Error(), "unexpected type for duration") {
        log.Printf("duration encoding drift: %v", err)
        return nil, nil
    }
    return nil, err
}

Prevention

When it happens

Trigger: Calling DurationMs() when the bridge returns a non-nil value of a type other than int64 for "duration_ms" (e.g. float64 after a native encoding change).

Common situations: Version drift between the baml Go bindings and the native runtime changing numeric encodings; patched or custom cffi decoders returning wrapped numbers.

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

Appendix: source

Thrown at engine/language_client_go/pkg/rawobjects_timing.go:53

		return 0, fmt.Errorf("unexpected type for start time: %T", result)
	}

	return startTime, nil
}

func (t *timing) DurationMs() (*int64, error) {
	result, err := raw_objects.CallMethod(t, "duration_ms", nil)
	if err != nil {
		return nil, fmt.Errorf("failed to get duration: %w", err)
	}

	if result == nil {
		return nil, nil
	}

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

	return &duration, nil
}

View on GitHub (pinned to bd85ce9dee)