BoundaryML/baml · error

%s

Error message

%s

What it means

After successfully unmarshaling the FFI response, decodeAsyncResponse checks whether the InvocationResponse holds an Error oneof; if so, it surfaces the native BAML runtime's error message verbatim via fmt.Errorf("%s", ...). This is the pass-through channel for errors that occurred inside the BAML runtime (compile errors, missing functions, LLM provider failures).

Solutions

  1. Read the wrapped %s message — it is the native runtime's own diagnostic (e.g. 'function X not found' or 'failed to parse') and fix the named cause
  2. Validate the function name exists in your baml_src directory and matches the generated client
  3. Run `baml-cli dev` or `baml-cli test` locally to catch compile errors in .baml files before runtime
  4. Verify provider credentials (OPENAI_API_KEY etc.) are present in the env vars passed at runtime creation

Example fix

// before
result, err := baml.CallFunction(ctx, "ExtractReusme", params) // typo'd function
// after
result, err := baml.CallFunction(ctx, "ExtractResume", params) // matches fn ExtractResume in baml_src
Defensive patterns

Strategy: try-catch

Validate before calling

if !baml.FunctionExists(ctx, "ExtractResume") {
    return fmt.Errorf("function ExtractResume not defined in baml_src")
}

Try / catch

result, err := baml.CallFunction(ctx, fnName, args)
var rtErr *baml.RuntimeError
if errors.As(err, &rtErr) {
    log.Errorf("baml runtime error: %s", rtErr.Error()) // native message
}

Prevention

When it happens

Trigger: Calling a BAML function (CallFunctionFromC / stream / parse / BuildRequestFromC / CancelFunctionCall) whose native execution returned InvocationResponse_Error — e.g. unknown function name, baml_src compile error, or provider/API failure inside the runtime.

Common situations: Calling a function name that doesn't exist in baml_src; a syntax error in a .baml file; expired or invalid LLM API key passed via env vars; malformed arguments that fail runtime type checking.

Related errors


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

Appendix: source

Thrown at engine/language_client_go/baml_go/exports.go:94

func decodeAsyncResponse(buf C.Buffer) error {
	defer C.WrapFreeBuffer(buf)

	// Empty buffer means success (task was spawned)
	if buf.ptr == nil || buf.len == 0 {
		return nil
	}

	content_bytes := C.GoBytes(unsafe.Pointer(buf.ptr), C.int32_t(buf.len))

	var response cffi.InvocationResponse
	if err := proto.Unmarshal(content_bytes, &response); err != nil {
		return fmt.Errorf("failed to unmarshal FFI response: %w", err)
	}

	// Check if response contains an error
	switch response.GetResponse().(type) {
	case *cffi.InvocationResponse_Error:
		return fmt.Errorf("%s", response.GetError())
	default:
		// Success or nil response means success
		return nil
	}
}

func CallFunctionFromC(runtime unsafe.Pointer, functionName string, encodedArgs []byte, id uint32) error {
	cFunctionName := C.CString(functionName)
	defer C.free(unsafe.Pointer(cFunctionName))

	cEncodedArgs := (*C.char)(unsafe.Pointer(&encodedArgs[0]))

	result := C.WrapCallFunctionFromC(runtime, cFunctionName, cEncodedArgs, C.uintptr_t(len(encodedArgs)), C.uint32_t(id))

	return decodeAsyncResponse(result)
}

func CallFunctionStreamFromC(runtime unsafe.Pointer, functionName string, encodedArgs []byte, id uint32) error {

View on GitHub (pinned to bd85ce9dee)