{"record":{"id":"6a3f30f8d7ada072","repo":"BoundaryML/baml","slug":"unexpected-type-for-class-property-builder-t","errorCode":null,"errorMessage":"unexpected type for class property builder: %T","messagePattern":"unexpected type for class property builder: %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/language_client_go/pkg/rawobjects_class_builder.go","lineNumber":75,"sourceCode":"\t}\n\n\treturn rawObjectsCast, nil\n}\n\n// AddProperty adds a new property to the class\nfunc (cb *classBuilder) AddProperty(name string, fieldType Type) (ClassPropertyBuilder, error) {\n\targs := map[string]interface{}{\n\t\t\"name\":       name,\n\t\t\"field_type\": fieldType,\n\t}\n\tresult, err := raw_objects.CallMethod(cb, \"add_property\", args)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tclassPropertyBuilder, ok := result.(ClassPropertyBuilder)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"unexpected type for class property builder: %T\", result)\n\t}\n\n\treturn classPropertyBuilder, nil\n}\n\n// Property gets a specific property from the class\nfunc (cb *classBuilder) Property(name string) (ClassPropertyBuilder, error) {\n\targs := map[string]interface{}{\n\t\t\"name\": name,\n\t}\n\tresult, err := raw_objects.CallMethod(cb, \"property\", args)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tclassPropertyBuilder, ok := result.(ClassPropertyBuilder)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"unexpected type for class property builder: %T\", result)","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_go/pkg/rawobjects_class_builder.go#L57-L93","documentation":"ClassBuilder.AddProperty() invokes the runtime's `add_property` method over FFI and asserts the returned value is a ClassPropertyBuilder. When the runtime returns any other Go type (nil, a raw pointer, a string, etc.), the assertion fails and this error is returned. It means the FFI call did not honor the expected return contract, usually due to a bindings/runtime version mismatch or an upstream failure that degraded the result.","triggerScenarios":"Calling AddProperty(name, fieldType) on a class builder when CallMethod returns a non-ClassPropertyBuilder value — e.g. nil after a failed mutation, or a wrong object type because the property name/field_type arguments were rejected upstream without raising.","commonSituations":"Building dynamic classes with a Go client and native runtime built from different commits; passing a Type object that the runtime could not resolve, causing a fallback result; a stale shared library after upgrading BAML.","solutions":["Ensure the Go bindings and BAML runtime versions match exactly; upgrade both together.","Log the %T value from the error and check whether it is nil, indicating the runtime returned nothing — inspect the add_property call arguments.","Retry the operation with a freshly constructed ClassBuilder in case the object's runtime state is corrupt.","Report to BAML maintainers with the error text if versions match."],"exampleFix":"// before (caller, unguarded)\nprop, err := classBuilder.AddProperty(\"score\", myType)\n// after\nprop, err := classBuilder.AddProperty(\"score\", myType)\nif err != nil {\n    return nil, fmt.Errorf(\"AddProperty failed, check baml runtime/binding version parity: %w\", err)\n}","handlingStrategy":"try-catch","validationCode":"// Ensure fieldType came from the same runtime before calling:\n// if fieldType == nil { return errors.New(\"fieldType required\") }","typeGuard":"func isClassPropertyBuilder(result any) bool {\n    _, ok := result.(ClassPropertyBuilder)\n    return ok\n}","tryCatchPattern":"prop, err := classBuilder.AddProperty(name, fieldType)\nif err != nil {\n    if strings.Contains(err.Error(), \"unexpected type for class property builder\") {\n        return nil, fmt.Errorf(\"AddProperty FFI contract violation (check version parity): %w\", err)\n    }\n    return nil, err\n}","preventionTips":["Keep Go bindings and native runtime on identical versions","Pass only Type objects obtained from the same runtime instance","Rebuild the runtime when upgrading the Go module"],"tags":["go","ffi","type-assertion","baml"],"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-14T05:17:10.506Z"}