BoundaryML/baml · error

unexpected type for literal bool type: %T

Error message

unexpected type for literal bool type: %T

What it means

TypeBuilder.LiteralBool() builds a bool-literal FieldType and asserts the FFI callback result implements the Type interface. A non-Type result (normally nil from a failed native call) triggers this internal-invariant error. It means the type-builder bridge returned an unexpected object.

Solutions

  1. Regenerate the BAML client so the Go bindings match the engine version (baml-cli generate).
  2. Ensure the TypeBuilder is created from a valid, live runtime rather than a zero-value struct.
  3. Upgrade engine/language_client_go and the baml CLI together to the latest release.
  4. Capture the %T value and file an issue at github.com/boundaryml/baml if the mismatch persists.

Example fix

// before
lit, err := zeroBuilder.LiteralBool(true) // no FFI state -> nil result

// after
tb := runtime.NewTypeBuilder()
lit, err := tb.LiteralBool(true)
if err != nil {
    return fmt.Errorf("build literal bool: %w", err)
}
Defensive patterns

Strategy: try-catch

Validate before calling

if tb == nil {
    return nil, errors.New("type builder not initialized")
}

Type guard

func hasRuntime(tb baml.TypeBuilder) bool { return tb.Runtime() != nil }

Try / catch

lit, err := tb.LiteralBool(v)
if err != nil {
    return nil, fmt.Errorf("LiteralBool(%v) failed: %w", v, err)
}

Prevention

When it happens

Trigger: Calling TypeBuilder.LiteralBool(true/false) when the underlying native builder call fails or returns a value failing the `result.(Type)` assertion.

Common situations: Version mismatch between the Go BAML client and the embedded engine library; using a TypeBuilder after its runtime was dropped; programmatically constructed builders missing FFI state.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12). Data as JSON: /api/errors/27a5be476736f4a1. Report an issue: GitHub.

Appendix: source

Thrown at engine/language_client_go/pkg/rawobjects_type_builder.go:141

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

	return typ, nil
}

func (tb *typeBuilder) LiteralBool(value bool) (Type, error) {
	args := map[string]interface{}{
		"value": value,
	}
	result, err := raw_objects.CallMethod(tb, "literal_bool", args)
	if err != nil {
		return nil, err
	}

	typ, ok := result.(Type)
	if !ok {
		return nil, fmt.Errorf("unexpected type for literal bool type: %T", result)
	}

	return typ, nil
}

// Composite types
func (tb *typeBuilder) Map(key Type, value Type) (Type, error) {
	args := map[string]interface{}{
		"key":   key,
		"value": value,
	}
	result, err := raw_objects.CallMethod(tb, "map", args)
	if err != nil {
		return nil, err
	}

	typ, ok := result.(Type)
	if !ok {

View on GitHub (pinned to bd85ce9dee)