{"record":{"id":"b74e1b09e1265811","repo":"BoundaryML/baml","slug":"unexpected-type-for-class-type-t","errorCode":null,"errorMessage":"unexpected type for class type: %T","messagePattern":"unexpected type for class type: %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/language_client_go/pkg/rawobjects_class_builder.go","lineNumber":36,"sourceCode":"\treturn cffi.BamlObjectType_OBJECT_CLASS_BUILDER\n}\n\nfunc newClassBuilder(ptr int64, rt unsafe.Pointer) ClassBuilder {\n\tbldr := classBuilder{raw_objects.FromPointer(ptr, rt), llmRenderableObject{}}\n\tbldr.llmRenderableObject = llmRenderableObject{&bldr}\n\treturn &bldr\n}\n\n// Type returns the type definition for this class\nfunc (cb *classBuilder) Type() (Type, error) {\n\tresult, err := raw_objects.CallMethod(cb, \"type_\", 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 class type: %T\", result)\n\t}\n\n\treturn typ, nil\n}\n\n// ListProperties returns all properties in the class\nfunc (cb *classBuilder) ListProperties() ([]ClassPropertyBuilder, error) {\n\tresult, err := raw_objects.CallMethod(cb, \"list_properties\", nil)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\trawObjects, ok := result.([]raw_objects.RawPointer)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"unexpected type for class property builders: %T\", result)\n\t}\n\n\trawObjectsCast := make([]ClassPropertyBuilder, len(rawObjects))","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_go/pkg/rawobjects_class_builder.go#L18-L54","documentation":"The class builder's Type method invokes an internal builder call and asserts the generic result is convertible to the Type interface. If the underlying value is a different kind (e.g. the object refers to an enum, literal, or union type rather than a class type), the assertion fails and this error reports the actual Go type.","triggerScenarios":"Calling Type() on a class builder result whose underlying representation is not a class Type — e.g. using the builder API on a type wrapper that resolves to an enum or primitive, or passing the wrong builder object type through the generic internal call path.","commonSituations":"Confusing class builders with enum/union builders in generated client code, refactoring generated code by hand, or calling Type() on the wrong builder returned from a registry lookup.","solutions":["Check the %T in the message to see what you actually got; use the corresponding builder method for that kind.","Ensure you obtained the builder from the class-specific accessor (e.g. tb.ClassName() style) rather than a generic type lookup.","Regenerate the BAML client so generated builders match your baml_schema sources.","Guard with a comma-ok type assertion on the returned value before use if the kind can vary."],"exampleFix":"// before\ntyp, err := builder.Type() // builder is actually an enum builder\n\n// after\nif clsBuilder, ok := builder.(ClassBuilder); ok {\n    typ, err = clsBuilder.Type()\n} else {\n    return fmt.Errorf(\"expected class builder, got %T\", builder)\n}","handlingStrategy":"type-guard","validationCode":"func isClassBuilder(b any) bool {\n\t_, ok := b.(ClassBuilder)\n\treturn ok\n}","typeGuard":"func toClassBuilder(b any) (ClassBuilder, error) {\n\tcb, ok := b.(ClassBuilder)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"not a class builder: %T\", b)\n\t}\n\treturn cb, nil\n}","tryCatchPattern":"typ, err := builder.Type()\nif err != nil {\n\tif strings.Contains(err.Error(), \"unexpected type for class type\") {\n\t\treturn fmt.Errorf(\"wrong builder kind used: %w\", err)\n\t}\n\treturn err\n}","preventionTips":["Use class-specific builder accessors from generated code","Don't hand-edit generated builder code","Regenerate clients after schema changes"],"tags":["go","type-assertion","builder","class"],"backgroundTag":"type-mismatch","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}