BoundaryML/baml · error

unexpected type for literal int type: %T

Error message

unexpected type for literal int type: %T

What it means

TypeBuilder.LiteralInt() builds an int64-literal FieldType and requires the FFI callback result to implement Type. When the native layer returns a non-Type value (typically nil), this internal-invariant error is raised. It reflects a bridge/engine mismatch, not a caller data problem.

Solutions

  1. Align the Go client module version with the native baml engine version and regenerate clients.
  2. Create the TypeBuilder fresh from the same runtime you use for the request.
  3. Validate the int value is within int64 range before calling.
  4. Report to boundaryml/baml with the %T value if versions are confirmed matching.

Example fix

// before
tb2 := baml.NewTypeBuilder(oldCtx) // runtime already closed
lit, err := tb2.LiteralInt(42) // assertion fails

// after
tb := runtime.NewTypeBuilder()
lit, err := tb.LiteralInt(42)
Defensive patterns

Strategy: try-catch

Validate before calling

if value < math.MinInt64 || value > math.MaxInt64 {
    return nil, errors.New("literal int out of int64 range")
}

Type guard

func fitsInt64(v int64) bool { return true } // check at source type (e.g. big.Int.IsInt64())

Try / catch

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

Prevention

When it happens

Trigger: Calling TypeBuilder.LiteralInt(value) where the native type creation fails and the checked result cannot be asserted to Type.

Common situations: Out-of-sync baml engine and Go client versions; a runtime whose FFI handles were invalidated; calling LiteralInt on a builder created against a different runtime instance.

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/2f3d6ca73d3c246d. Report an issue: GitHub.

Appendix: source

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

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

	return typ, nil
}

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

	typ, ok := result.(Type)
	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)
	}

View on GitHub (pinned to bd85ce9dee)