BoundaryML/baml · error

unexpected type for log type: %T

Error message

unexpected type for log type: %T

What it means

Returned by LogType() when the 'log_type' call succeeded but the decoded value failed the `result.(string)` assertion, meaning the runtime returned a non-string Go value. This guards the FFI contract between the Go client and the Rust BAML runtime; hitting it implies the runtime's representation of log_type differs from what the client expects — a contract/version mismatch or object corruption, not a user input problem.

Source

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

	}

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

	return name, nil
}

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

	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
}

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Regenerate the Go client (`baml generate`) to match the installed BAML runtime.
  2. Note the %T type printed in the message to identify what was actually returned.
  3. Use the log only while its function stream is valid; recreate access from the live response.
  4. File a bug with BAML (include the printed Go type and versions) if it occurs on a fresh, valid object.
Defensive patterns

Strategy: type-guard

Validate before calling

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

Type guard

func logTypeIsString(v any) (string, bool) {
    s, ok := v.(string)
    return s, ok
}

Try / catch

lt, err := fnLog.LogType()
if err != nil {
    if strings.Contains(err.Error(), "unexpected type for log type:") {
        return "", fmt.Errorf("log_type contract mismatch (check client/runtime versions): %w", err)
    }
    return "", err
}

Prevention

When it happens

Trigger: The Rust runtime decodes log_type into a non-string object; client/runtime version skew changing field representation; corrupted stale functionLog objects.

Common situations: Mixing a newer BAML engine with an older generated Go client; reusing logs after stream teardown; a decodeObjectResponse variant bug.

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