BoundaryML/baml · error

failed to create type builder

Error message

failed to create type builder: %w

What it means

NewTypeBuilder asks the Rust runtime to create an OBJECT_TYPE_BUILDER raw object; if the runtime returns an error, it is wrapped as 'failed to create type builder'. The type builder is used for constructing dynamic types at runtime, so this failure blocks all subsequent dynamic-type construction.

Solutions

  1. Check the wrapped inner error for the runtime's specific failure reason
  2. Verify the native BAML runtime version supports type builders (upgrade if old)
  3. Confirm the runtime loaded correctly (correct binary for platform/arch)
  4. Report upstream with the error chain if it reproduces on a current, clean install
Defensive patterns

Strategy: try-catch

Try / catch

tb, err := runtime.NewTypeBuilder()
if err != nil {
    return nil, fmt.Errorf("type builder unavailable (check runtime version/support): %w", err)
}
defer tb.Destroy() // or whatever cleanup the API provides

Prevention

When it happens

Trigger: Calling NewTypeBuilder() when raw_objects.NewRawObject(OBJECT_TYPE_BUILDER, nil) fails — typically a runtime-level allocation or cffi dispatch failure, or a runtime build that does not support type builders.

Common situations: A native runtime binary too old to support object type builders; corrupted or incompatible runtime after upgrade; resource exhaustion in the embedded runtime.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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

Appendix: source

Thrown at engine/language_client_go/pkg/rawobjects_constructors.go:112

	return r.newMediaFromBase64(MediaType_Image, base64, mimeType)
}

func (r *BamlRuntime) NewAudioFromBase64(base64 string, mimeType *string) (Audio, error) {
	return r.newMediaFromBase64(MediaType_Audio, base64, mimeType)
}

func (r *BamlRuntime) NewPDFFromBase64(base64 string, mimeType *string) (PDF, error) {
	return r.newMediaFromBase64(MediaType_PDF, base64, mimeType)
}

func (r *BamlRuntime) NewVideoFromBase64(base64 string, mimeType *string) (Video, error) {
	return r.newMediaFromBase64(MediaType_Video, base64, mimeType)
}

func (r *BamlRuntime) NewTypeBuilder() (TypeBuilder, error) {
	ptr, err := raw_objects.NewRawObject(r.runtime, cffi.BamlObjectType_OBJECT_TYPE_BUILDER, nil)
	if err != nil {
		return nil, fmt.Errorf("failed to create type builder: %w", err)
	}

	as_type_builder, ok := ptr.(*typeBuilder)
	if !ok {
		return nil, fmt.Errorf("unexpected type for type builder creation: %T", ptr)
	}

	return as_type_builder, nil
}

View on GitHub (pinned to bd85ce9dee)