{"record":{"id":"6b77a5238f6cbb68","repo":"BoundaryML/baml","slug":"unexpected-type-for-int-type-t","errorCode":null,"errorMessage":"unexpected type for int type: %T","messagePattern":"unexpected type for int type: %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/language_client_go/pkg/rawobjects_type_builder.go","lineNumber":47,"sourceCode":"\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}\n\nfunc (tb *typeBuilder) Float() (Type, error) {\n\tresult, err := raw_objects.CallMethod(tb, \"float\", 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 float type: %T\", result)\n\t}\n\n\treturn typ, nil\n}","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_go/pkg/rawobjects_type_builder.go#L29-L65","documentation":"typeBuilder.Int() calls the FFI method \"int\" and asserts the returned any implements the baml Type interface. A non-Type result (unwrapped raw pointer, nil, or wrong wrapper kind) triggers this error. It is a CFFI decoder contract failure, not an invalid argument from the caller.","triggerScenarios":"Calling TypeBuilder.Int() when the underlying \"int\" method returns an object the Go bindings cannot wrap as a Type.","commonSituations":"Binding/native runtime version drift; stale generated wrapper registry; TypeBuilder instance created by a different runtime than the decoder expects.","solutions":["Inspect %T in the error to identify the unwrapped object kind.","Upgrade the baml Go module to match your native BAML runtime version.","Regenerate/refresh cffi wrapper code if you maintain custom builds.","File an upstream issue with the printed %T if versions are already aligned."],"exampleFix":"// before\ntyp, err := tb.Int()\nif err != nil {\n    return err\n}\n\n// after: log the underlying type to aid diagnosis\ntyp, err := tb.Int()\nif err != nil {\n    return fmt.Errorf(\"tb.Int (update baml bindings if this persists): %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.Int()\nif err != nil {\n    log.Printf(\"Int() decode failure (check binding/runtime sync): %v\", err)\n    return fmt.Errorf(\"int type build failed: %w\", err)\n}","preventionTips":["Pin baml Go module and BAML CLI to the same release.","Regenerate cffi wrappers after building BAML from source.","Log %T from the error when filing issues."],"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"}