{"record":{"id":"b516ba14a30319dc","repo":"BoundaryML/baml","slug":"encoding-type-builder-w","errorCode":null,"errorMessage":"encoding type builder: %w","messagePattern":"encoding type builder: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/language_client_go/pkg/rawobjects_function_args.go","lineNumber":69,"sourceCode":"\tvar collectors []*cffi.BamlObjectHandle\n\tif args.Collectors != nil {\n\t\tfor _, collector := range args.Collectors {\n\t\t\tif collector == nil {\n\t\t\t\treturn nil, fmt.Errorf(\"nil collector found in collectors\")\n\t\t\t}\n\t\t\tencodedCollector := raw_objects.EncodeRawObject(collector)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"encoding collector: %w\", err)\n\t\t\t}\n\t\t\tcollectors = append(collectors, encodedCollector)\n\t\t}\n\t}\n\n\tvar typeBuilder *cffi.BamlObjectHandle\n\tif args.TypeBuilder != nil {\n\t\tencodedTypeBuilder := raw_objects.EncodeRawObject(args.TypeBuilder)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"encoding type builder: %w\", err)\n\t\t}\n\t\ttypeBuilder = encodedTypeBuilder\n\t}\n\n\tvar tags []*cffi.HostMapEntry\n\tif args.Tags != nil {\n\t\tfor key, value := range args.Tags {\n\t\t\ttags = append(tags, &cffi.HostMapEntry{\n\t\t\t\tKey: &cffi.HostMapEntry_StringKey{StringKey: key},\n\t\t\t\tValue: &cffi.HostValue{\n\t\t\t\t\tValue: &cffi.HostValue_StringValue{\n\t\t\t\t\t\tStringValue: value,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t})\n\t\t}\n\t}\n","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_go/pkg/rawobjects_function_args.go#L51-L87","documentation":"A TypeBuilder attached to BamlFunctionArguments is encoded into a BamlObjectHandle via raw_objects.EncodeRawObject before the call. Wrapping failure means the type builder's raw object could not be converted into a host-side handle, so the call cannot proceed.","triggerScenarios":"Passing a TypeBuilder created outside the current runtime context, a builder whose registration of classes/enums partially failed, or a builder whose underlying raw object pointer is stale/freed.","commonSituations":"Reusing one TypeBuilder across multiple runtime instances; building a TypeBuilder and letting it go out of scope/GC before the call; constructing TypeBuilder manually without the official constructor in a version-skewed build.","solutions":["Create the TypeBuilder via tb.NewTypeBuilder (or runtime's builder API) and use it only with the matching runtime","Keep a Go reference to the TypeBuilder alive until the function call completes","Recreate the TypeBuilder in the same scope as the call if it was shared across runtimes","Match BAML Go bindings and runtime versions (regenerate client)"],"exampleFix":"// before\ntb := &TypeBuilder{} // zero value, not registered with runtime\nargs.TypeBuilder = tb\n// after\ntb := tb.NewTypeBuilder()\ntb.Class(\"User\").Field(\"id\", \"string\")\nargs.TypeBuilder = tb","handlingStrategy":"validation","validationCode":"// ensure type builder is constructed and registered\ntb := tb.NewTypeBuilder()\ntb.Class(\"User\").Field(\"id\", \"string\")\nif tb == nil { return errors.New(\"type builder not initialized\") }","typeGuard":null,"tryCatchPattern":"err = runtime.CallFunction(ctx, \"Fn\", params, kwargs, args)\nif err != nil && strings.Contains(err.Error(), \"encoding type builder\") {\n    return fmt.Errorf(\"recreate TypeBuilder for this runtime: %w\", err)\n}","preventionTips":["Always build TypeBuilders with the official constructor, never zero-value structs","Scope the TypeBuilder to the same runtime instance used in the call","Hold the builder reference until the call returns"],"tags":["go","serialization","ffi","type-builder"],"backgroundTag":"invalid-argument-value","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}