BoundaryML/baml · error
unexpected type for logs: %T
Error message
unexpected type for logs: %T
What it means
Thrown by Collector.Logs() in engine/language_client_go/pkg/rawobjects_collector.go:63 when the underlying FFI CallMethod("logs") returns a value that is not a []raw_objects.RawPointer slice. The BAML Go client unmarshals raw C++ collector objects into typed Go values; if the runtime returns something unexpected, this internal type-assertion guard fires. It almost always indicates an FFI/version mismatch or a corrupted raw object rather than user error.
Source
Thrown at engine/language_client_go/pkg/rawobjects_collector.go:63
}
name, ok := result.(string)
if !ok {
return "", fmt.Errorf("unexpected type for name: %T", result)
}
return name, nil
}
func (c *collector) Logs() ([]FunctionLog, error) {
result, err := raw_objects.CallMethod(c, "logs", nil)
if err != nil {
return nil, fmt.Errorf("failed to get logs: %w", err)
}
logs, ok := result.([]raw_objects.RawPointer)
if !ok {
return nil, fmt.Errorf("unexpected type for logs: %T", result)
}
functionLogs := make([]FunctionLog, len(logs))
for i, log := range logs {
cast, ok := log.(FunctionLog)
if !ok {
return nil, fmt.Errorf("unexpected type in logs: %T", log)
}
functionLogs[i] = cast
}
return functionLogs, nil
}
func (c *collector) Last() (FunctionLog, error) {
result, err := raw_objects.CallMethod(c, "last", nil)
if err != nil {
return nil, fmt.Errorf("failed to get last log: %w", err)View on GitHub (pinned to bd85ce9dee)
Solutions
- Ensure the Go baml client version matches the native BAML runtime/binary version; rebuild and re-link.
- Upgrade github.com/boundaryml/baml Go package and regenerate any BAML client code.
- If reproducible, file a bug with the %T value printed in the message.
Example fix
// before
logs, err := collector.Logs()
// after
logs, err := collector.Logs()
if err != nil {
var te *baml.TypeMismatchError
if errors.As(err, &te) { /* runtime/client version mismatch: reinstall matching baml binaries */ }
} Defensive patterns
Strategy: type-guard
Validate before calling
if collector == nil { return errors.New("collector not initialized") } Type guard
func safeLogs(c baml.Collector) ([]baml.FunctionLog, bool) {
logs, err := c.Logs()
if err != nil { return nil, false }
return logs, true
} Try / catch
logs, err := collector.Logs()
if err != nil {
if strings.Contains(err.Error(), "unexpected type") {
// Go client / native runtime version mismatch: fail fast with guidance
}
return err
} Prevention
- Pin the BAML Go client and native binary to the same version.
- Rebuild the client after upgrading the BAML runtime.
- Log the full error (it includes the offending %T) when filing bugs.
When it happens
Trigger: Calling collector.Logs() when the BAML runtime's 'logs' method returns a non-slice raw object — typically from a version mismatch between the Go client and the native BAML runtime, or a raw object registered under the wrong object type.
Common situations: Mixed-version baml-go bindings and native binaries; upgrading the BAML runtime without rebuilding the Go client; corrupted Collector handle after runtime restart.
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 in logs: %T
- unexpected type for last log: %T %v
- unexpected type for log by id: %T
- unexpected type for clear result: %T
- failed to get usage: %w
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/7b02270ea745d885.
Report an issue: GitHub.