{"record":{"id":"b93305a94d1a4a7b","repo":"BoundaryML/baml","slug":"unexpected-type-for-type-builder-creation-t","errorCode":null,"errorMessage":"unexpected type for type builder creation: %T","messagePattern":"unexpected type for type builder creation: %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/language_client_go/pkg/rawobjects_constructors.go","lineNumber":117,"sourceCode":"}\n\nfunc (r *BamlRuntime) NewPDFFromBase64(base64 string, mimeType *string) (PDF, error) {\n\treturn r.newMediaFromBase64(MediaType_PDF, base64, mimeType)\n}\n\nfunc (r *BamlRuntime) NewVideoFromBase64(base64 string, mimeType *string) (Video, error) {\n\treturn r.newMediaFromBase64(MediaType_Video, base64, mimeType)\n}\n\nfunc (r *BamlRuntime) NewTypeBuilder() (TypeBuilder, error) {\n\tptr, err := raw_objects.NewRawObject(r.runtime, cffi.BamlObjectType_OBJECT_TYPE_BUILDER, nil)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to create type builder: %w\", err)\n\t}\n\n\tas_type_builder, ok := ptr.(*typeBuilder)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"unexpected type for type builder creation: %T\", ptr)\n\t}\n\n\treturn as_type_builder, nil\n}\n","sourceCodeStart":99,"sourceCodeEnd":122,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_go/pkg/rawobjects_constructors.go#L99-L122","documentation":"After NewRawObject succeeds, NewTypeBuilder asserts the result is a *typeBuilder. If the runtime returned a different concrete type, this error is thrown. It is an internal consistency check that the cffi object factory returned the expected Go wrapper for OBJECT_TYPE_BUILDER.","triggerScenarios":"Calling NewTypeBuilder() when the returned raw object fails the *typeBuilder assertion — caused by bindings/runtime version mismatch or a NewRawObject dispatch bug, not caller input.","commonSituations":"Partial SDK upgrades leaving generated wrappers out of sync with the native library; patched engine builds.","solutions":["Match Go SDK and native runtime versions (`go mod tidy`, clean reinstall)","Rebuild or re-download the native runtime binary","Inspect the %T value in the message and file an upstream bug if reproducible on a clean install"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":"func asTypeBuilder(v any) (*typeBuilder, bool) {\n    tb, ok := v.(*typeBuilder)\n    return tb, ok\n}","tryCatchPattern":"tb, err := runtime.NewTypeBuilder()\nif err != nil {\n    if strings.Contains(err.Error(), \"unexpected type for type builder creation\") {\n        return nil, fmt.Errorf(\"baml bindings/runtime version mismatch: %w\", err)\n    }\n    return nil, err\n}","preventionTips":["Upgrade SDK module and native runtime together","Pin versions and avoid partial updates","Log the %T value when reporting the bug upstream"],"tags":["go","baml-runtime","type-assertion","internal"],"backgroundTag":"internal-invariant-violation","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}