BoundaryML/baml · error
unexpected type for calls count: %T
Error message
unexpected type for calls count: %T
What it means
CallsCount() type-asserts the bridge result of the 'calls_count' method to Go int; when the runtime returns any other type (e.g. int64, float64, or nil) the assertion fails and this error is thrown. It protects callers from silent numeric-type drift across the runtime boundary.
Source
Thrown at engine/language_client_go/pkg/rawobjects_function_log.go:119
}
response, ok := result.(string)
if !ok {
return "", fmt.Errorf("unexpected type for raw LLM response: %T", result)
}
return response, nil
}
func (f *functionLog) CallsCount() (int, error) {
result, err := raw_objects.CallMethod(f, "calls_count", nil)
if err != nil {
return 0, fmt.Errorf("failed to get calls count: %w", err)
}
count, ok := result.(int)
if !ok {
return 0, fmt.Errorf("unexpected type for calls count: %T", result)
}
return count, nil
}
func (f *functionLog) Calls() ([]LLMCall, error) {
result, err := raw_objects.CallMethod(f, "calls", nil)
if err != nil {
return nil, fmt.Errorf("failed to get calls: %w", err)
}
result_cast := result.([]raw_objects.RawPointer)
calls := make([]LLMCall, len(result_cast))
for i, call := range result_cast {
calls[i] = call.(LLMCall)
}
View on GitHub (pinned to bd85ce9dee)
Solutions
- Check %T in the error to see the actual numeric type returned
- Convert the bridge's number type (e.g. int64 or float64) explicitly before or after the assertion
- Align the bridge marshaling config so numbers decode as int
Example fix
// before
count, ok := result.(int)
if !ok {
return 0, fmt.Errorf("unexpected type for calls count: %T", result)
}
// after
var count int
switch v := result.(type) {
case int:
count = v
case int64:
count = int(v)
case float64:
count = int(v)
default:
return 0, fmt.Errorf("unexpected type for calls count: %T", result)
} Defensive patterns
Strategy: type-guard
Type guard
func asInt(v any) (int, bool) {
switch n := v.(type) {
case int:
return n, true
case int64:
return int(n), true
case float64:
return int(n), true
}
return 0, false
} Try / catch
count, err := flog.CallsCount()
if err != nil {
if strings.Contains(err.Error(), "unexpected type for calls count") {
return 0, fmt.Errorf("runtime returned non-int count: %w", err)
}
return 0, err
} Prevention
- Align bridge marshaling so integers decode as int
- Tolerate int64/float64 numerics from runtimes with unbounded ints
- Pin runtime and binding versions together
When it happens
Trigger: Calling FunctionLog.CallsCount() when the remote 'calls_count' method returns a numeric type other than Go int (int64/float64 from the marshaling layer) or nil.
Common situations: JSON/IPC marshaling that decodes numbers as float64 or int64 instead of int; runtime languages with unbounded integers returning bigint-like values; count unset so nil is returned.
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
- unexpected type for raw LLM response: %T
- unexpected type for class type: %T
- unexpected type for class property builders: %T
- unexpected type for class property builder: %T
- unexpected type for class property type: %T
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/fbcdfd2078ccbb0f.
Report an issue: GitHub.