BoundaryML/baml · error
unexpected type for bool type: %T
Error message
unexpected type for bool type: %T
What it means
typeBuilder.Bool() calls the FFI method "bool" and asserts the result implements the baml Type interface. When the bridge returns a value that is not a Type implementation, the assertion fails with this error. This is an internal decode/wrapping failure between the native BAML runtime and the Go bindings.
Solutions
- Check %T in the error to identify what the bridge returned.
- Update the baml Go module to match your native BAML runtime version.
- Regenerate wrapper code if using a from-source build.
- Escalate to boundaryml/baml with the printed type if versions are aligned.
Example fix
// before
boolTyp, err := tb.Bool()
if err != nil {
return err
}
// after
boolTyp, err := tb.Bool()
if err != nil {
return fmt.Errorf("bool type build failed (verify baml Go bindings match native runtime): %w", err)
} Defensive patterns
Strategy: try-catch
Validate before calling
if tb == nil {
return errors.New("type builder is nil")
} Type guard
func isBamlType(v any) bool { _, ok := v.(baml.Type); return ok } Try / catch
typ, err := tb.Bool()
if err != nil {
log.Printf("Bool() decode failure: %v", err)
return fmt.Errorf("bool type build failed: %w", err)
} Prevention
- Keep baml Go bindings and native runtime on matching versions.
- Add type-builder basic-type tests to your upgrade checklist.
- Capture %T from the error message for diagnostics.
When it happens
Trigger: Calling TypeBuilder.Bool() when the underlying "bool" method returns an unwrapped raw object or nil instead of a Type.
Common situations: Go bindings out of sync with the native runtime; stale or custom-generated cffi wrapper registry; TypeBuilder created from an incompatible runtime instance.
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 float type: %T
- unexpected type for int type: %T
- unexpected type for string type: %T
- encoding type builder
- unexpected type for as_base64: %T
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/a510960c871cbbc9.
Report an issue: GitHub.
Appendix: source
Thrown at engine/language_client_go/pkg/rawobjects_type_builder.go:75
}
typ, ok := result.(Type)
if !ok {
return nil, fmt.Errorf("unexpected type for float type: %T", result)
}
return typ, nil
}
func (tb *typeBuilder) Bool() (Type, error) {
result, err := raw_objects.CallMethod(tb, "bool", nil)
if err != nil {
return nil, err
}
typ, ok := result.(Type)
if !ok {
return nil, fmt.Errorf("unexpected type for bool type: %T", result)
}
return typ, nil
}
func (tb *typeBuilder) Null() (Type, error) {
result, err := raw_objects.CallMethod(tb, "null", nil)
if err != nil {
return nil, err
}
typ, ok := result.(Type)
if !ok {
return nil, fmt.Errorf("unexpected type for null type: %T", result)
}
return typ, nil
}View on GitHub (pinned to bd85ce9dee)