{"record":{"id":"b04dbd8b20acbc83","repo":"BoundaryML/baml","slug":"unexpected-type-for-string-type-t","errorCode":null,"errorMessage":"unexpected type for string type: %T","messagePattern":"unexpected type for string type: %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/language_client_go/pkg/rawobjects_type_builder.go","lineNumber":33,"sourceCode":"\nfunc (tb *typeBuilder) ObjectType() cffi.BamlObjectType {\n\treturn cffi.BamlObjectType_OBJECT_TYPE_BUILDER\n}\n\nfunc newTypeBuilder(ptr int64, rt unsafe.Pointer) TypeBuilder {\n\treturn &typeBuilder{raw_objects.FromPointer(ptr, rt)}\n}\n\n// Basic types\nfunc (tb *typeBuilder) String() (Type, error) {\n\tresult, err := raw_objects.CallMethod(tb, \"string\", nil)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\ttyp, ok := result.(Type)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"unexpected type for string type: %T\", result)\n\t}\n\n\treturn typ, nil\n}\n\nfunc (tb *typeBuilder) Int() (Type, error) {\n\tresult, err := raw_objects.CallMethod(tb, \"int\", nil)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\ttyp, ok := result.(Type)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"unexpected type for int type: %T\", result)\n\t}\n\n\treturn typ, nil\n}","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_go/pkg/rawobjects_type_builder.go#L15-L51","documentation":"typeBuilder.String() calls the FFI method \"string\" on the TypeBuilder and asserts the result implements the baml Type interface. If the bridge returns something else (a raw pointer that was not wrapped into a Type, nil, etc.), the assertion fails and this error is thrown. It indicates the CFFI object decoder failed to produce a proper Type wrapper for the built type.","triggerScenarios":"Calling TypeBuilder.String() (in type-builder based schema construction, e.g. dynamic BAML types) when the underlying \"string\" method returns an unwrapped RawPointer or nil instead of a Type implementation.","commonSituations":"Go bindings out of sync with the native runtime so new type objects are not recognized by the wrapper registry; calling String() on a TypeBuilder obtained from an incompatible runtime; internal decoder registry missing the OBJECT_* mapping.","solutions":["Check the %T in the message: if it is a raw pointer type, your bindings cannot wrap this object - update the baml Go module.","Ensure TypeBuilder comes from the same baml runtime version as the bindings you compile against.","Rebuild/refresh generated cffi code (go mod tidy + upgrade) if the type registry is stale.","Report the missing Type wrapper to boundaryml/baml if versions are aligned."],"exampleFix":"// before\ntyp, err := tb.String()\nif err != nil {\n    return err\n}\n\n// after: retry with a freshly created TypeBuilder from the same runtime\nnewTB, err := rt.TypeBuilder()\nif err != nil {\n    return err\n}\ntyp, err := newTB.String()\nif err != nil {\n    return fmt.Errorf(\"string type build failed: %w\", err)\n}","handlingStrategy":"try-catch","validationCode":"if tb == nil {\n    return errors.New(\"type builder is nil\")\n}","typeGuard":"func isBamlType(v any) bool { _, ok := v.(baml.Type); return ok }","tryCatchPattern":"typ, err := tb.String()\nif err != nil {\n    if strings.Contains(err.Error(), \"unexpected type for string type\") {\n        return fmt.Errorf(\"baml bindings/runtime version mismatch: %w\", err)\n    }\n    return err\n}","preventionTips":["Create TypeBuilders from the same runtime version as your compiled bindings.","Run type-builder smoke tests (TestSimpleTypeBuilder-style) after version bumps.","Keep go.mod baml versions in sync with the deployed BAML runtime."],"tags":["go","ffi","type-builder","type-mismatch"],"backgroundTag":"type-mismatch","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"}