BoundaryML/baml · error

unexpected type for timing: %T

Error message

unexpected type for timing: %T

What it means

Returned by Timing() when the 'timing' call succeeded but the value failed the `result.(Timing)` assertion — the runtime returned a Go value that is not the Timing interface/struct the client expects. This is a client-runtime FFI contract guard: the decoded object is of an unexpected concrete type, pointing to version skew, a decoder bug, or a corrupted object rather than anything the caller did wrong.

Source

Thrown at engine/language_client_go/pkg/rawobjects_function_log.go:77

	}

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

	return logType, nil
}

func (f *functionLog) Timing() (Timing, error) {
	result, err := raw_objects.CallMethod(f, "timing", nil)
	if err != nil {
		return nil, fmt.Errorf("failed to get timing: %w", err)
	}

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

	return timing, nil
}

func (f *functionLog) Usage() (Usage, error) {
	result, err := raw_objects.CallMethod(f, "usage", nil)
	if err != nil {
		return nil, fmt.Errorf("failed to get usage: %w", err)
	}

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

	return usage, nil
}

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Regenerate the Go client so its cffi bindings match the BAML runtime version.
  2. Check the %T in the message to see the actual returned type.
  3. Only consume the FunctionLog while its stream/request is still alive.
  4. Report upstream with versions and the printed type if reproducible on a fresh object.
Defensive patterns

Strategy: type-guard

Validate before calling

if fnLog == nil {
    return errors.New("function log is nil; cannot read Timing")
}

Type guard

func timingIsTiming(v any) bool {
    _, ok := v.(Timing)
    return ok
}

Try / catch

timing, err := fnLog.Timing()
if err != nil {
    if strings.Contains(err.Error(), "unexpected type for timing:") {
        return nil, fmt.Errorf("timing object contract mismatch (version skew?): %w", err)
    }
    return nil, err
}

Prevention

When it happens

Trigger: timing decodes into a different raw object class (e.g. a plain map/class instead of the Timing raw object); mismatched client and runtime versions; stale functionLog objects.

Common situations: Partial upgrade where the BAML engine emits a new timing representation but the Go client predates it; reusing logs post-stream; internal decode errors producing the wrong object variant.

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