BoundaryML/baml · error

internal error: attempted to register unknown function '%s'

Error message

internal error: attempted to register unknown function '%s'

What it means

registerFn() maps each known FFI symbol name to a C setter function via a switch; any name outside the fixed list of 13 expected functions hits the default branch and panics with this internal-error message (engine/language_client_go/baml_go/lib_common.go:245-247). This is an internal invariant violation: callers inside this package only ever pass hardcoded known names, so it should be unreachable in released code.

Source

Thrown at engine/language_client_go/baml_go/lib_common.go:246

		C.SetRegisterCallbacksFn(fnPtr)
	case "call_function_from_c":
		C.SetCallFunctionFromCFn(fnPtr)
	case "call_function_stream_from_c":
		C.SetCallFunctionStreamFromCFn(fnPtr)
	case "call_function_parse_from_c":
		C.SetCallFunctionParseFromCFn(fnPtr)
	case "build_request_from_c":
		C.SetBuildRequestFromCFn(fnPtr)
	case "cancel_function_call":
		C.SetCancelFunctionCallFn(fnPtr)
	case "call_object_constructor":
		C.SetCallObjectConstructorFn(fnPtr)
	case "call_object_method":
		C.SetCallObjectMethodFunctionFn(fnPtr)
	case "free_buffer":
		C.SetFreeBufferFn(fnPtr)
	default:
		panic(fmt.Sprintf("internal error: attempted to register unknown function '%s'", fnName))
	}
	return nil
}

func findOrDownloadLibrary() error {
	if bamlSharedLibraryPath != "" {
		_, err := os.Stat(bamlSharedLibraryPath)
		if err == nil {
			logger.Debug("Using BAML library path set via SetSharedLibraryPath()", "path", bamlSharedLibraryPath)
			return nil
		}
		err = fmt.Errorf("%w: path explicitly set via SetSharedLibraryPath() %s is invalid: %w", ErrLoadLibrary, bamlSharedLibraryPath, err)
		return err
	}

	envPath := os.Getenv(bamlLibraryPathEnv)
	if envPath != "" {
		_, err := os.Stat(envPath)

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Add a case for the function name in registerFn's switch that calls the corresponding C.Set*Fn setter with the looked-up fnPtr
  2. Add the matching extern setter to baml_cffi_wrapper.h / the C wrapper if the symbol is new
  3. Remove the stray l.registerFn("...") call in registerFunctions if the name was added by mistake
  4. If you hit this without modifying the library, report it as a bug to boundaryml/baml with the BAML_LOG=DEBUG output — it indicates a broken build of the package

Example fix

// before
l.registerFn("invoke_runtime_cli_v2") // no case in switch -> panic

// after
// in registerFunctions: keep l.registerFn("invoke_runtime_cli_v2") only if you also add:
case "invoke_runtime_cli_v2":
    C.SetInvokeRuntimeCliV2Fn(fnPtr)
Defensive patterns

Strategy: validation

Try / catch

// Not user-reachable; if hit in a fork, guard your registration changes:
func() {
    defer func() {
        if r := recover(); r != nil {
            log.Fatalf("baml registerFn bug: %v", r) // fail fast with the unknown fn name
        }
    }()
    // ... library init
}()

Prevention

When it happens

Trigger: Only reachable if the package source is modified to call registerFn with a function name that has no case in the switch (e.g. a developer adds l.registerFn("new_symbol") in registerFunctions without adding a corresponding case and C setter). Not triggerable from public API.

Common situations: A contributor adds a new FFI entry point to registerFunctions but forgets the switch case and the matching C.Set*Fn binding; merging partial patches to the FFI surface.

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/942983cc54a8dcf3. Report an issue: GitHub.