BoundaryML/baml · error

nil response

Error message

nil response

What it means

decodeObjectResponse received a nil *cffi.InvocationResponse pointer. The library requires a populated FFI invocation response to decode a raw BAML object; a nil pointer means the C bridge returned nothing at all, so decoding cannot proceed. This is an internal contract violation between the Go bindings and the C/CFFI layer rather than a user-facing error.

Source

Thrown at engine/language_client_go/baml_go/raw_objects/utils.go:205

	if err != nil {
		return nil, fmt.Errorf("failed to unmarshal content bytes: %w", err)
	}

	parsed, err := decodeObjectResponse(object.Runtime(), &content_holder)
	if err != nil {
		return nil, fmt.Errorf("failed to decode object response: %w", err)
	}

	return parsed, nil
}

type nilObject struct {
	any
}

func decodeObjectResponse(rt unsafe.Pointer, response *cffi.InvocationResponse) (any, error) {
	if response == nil {
		return nil, fmt.Errorf("nil response")
	}

	switch response.GetResponse().(type) {
	case *cffi.InvocationResponse_Error:
		return nil, fmt.Errorf("%s", response.GetError())
	case *cffi.InvocationResponse_Success:
		success := response.GetSuccess()
		switch success.Result.(type) {
		case *cffi.InvocationResponseSuccess_Object:
			object := success.GetObject()
			return decodeRawObject(rt, object)
		case *cffi.InvocationResponseSuccess_Objects:
			objects := success.GetObjects()
			parsed := make([]RawPointer, len(objects.Objects))
			for i, obj := range objects.Objects {
				decoded, err := decodeRawObject(rt, obj)
				if err != nil {
					return nil, fmt.Errorf("failed to decode object at index %d: %w", i, err)

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Reinstall / rebuild the BAML Go bindings so the native cffi library matches your baml_go version
  2. Verify the BAML runtime is initialized (e.g. BAML log/ensure initialized) before calling NewRawObject or CallMethod
  3. Check the FFI call site that produced the nil response for earlier errors that were swallowed
  4. Report to BAML maintainers with a minimal repro if the runtime is healthy

Example fix

// before
resp, _ := invoke()
raw, err := decodeObjectResponse(rt, resp)
// after
resp, err := invoke()
if err != nil { return err }
if resp == nil { return fmt.Errorf("runtime returned nil invocation response") }
raw, err := decodeObjectResponse(rt, resp)
Defensive patterns

Strategy: type-guard

Validate before calling

if resp == nil { return fmt.Errorf("no invocation response from BAML runtime") }

Type guard

func hasResponse(r *cffi.InvocationResponse) bool { return r != nil && r.GetResponse() != nil }

Try / catch

raw, err := decodeObjectResponse(rt, resp)
if err != nil {
  return fmt.Errorf("baml object decode failed: %w", err)
}

Prevention

When it happens

Trigger: NewRawObject or CallMethod invoked with a response pointer that is nil, i.e. the cffi runtime produced no InvocationResponse for the call.

Common situations: Corrupted or mismatched BAML native library installation, a failed FFI initialization that silently returns null, or calling functions before the runtime is properly initialized.

Related errors


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