{"record":{"id":"dc70bd2253930b89","repo":"BoundaryML/baml","slug":"unexpected-type-for-class-property-builders-t","errorCode":null,"errorMessage":"unexpected type for class property builders: %T","messagePattern":"unexpected type for class property builders: %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/language_client_go/pkg/rawobjects_class_builder.go","lineNumber":51,"sourceCode":"\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))\n\tfor i, rawObject := range rawObjects {\n\t\trawObjectsCast[i] = rawObject.(ClassPropertyBuilder)\n\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 {","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_go/pkg/rawobjects_class_builder.go#L33-L69","documentation":"BAML's Go client wraps dynamic class-builder objects that live behind an FFI boundary. When ListProperties() calls the remote `list_properties` method, it expects the runtime to hand back a []raw_objects.RawPointer; if the shared runtime returns any other Go type, this error is thrown instead of silently continuing. It signals a version or state mismatch between the Go bindings and the native BAML runtime, i.e. the FFI layer broke its documented return contract.","triggerScenarios":"Calling ClassBuilder.ListProperties() when the underlying CallMethod returns something other than []raw_objects.RawPointer — typically a nil result, a single raw pointer, or a deserialized map after a partial runtime failure.","commonSituations":"Mixing a Go client built against one BAML version with a native runtime library of another; a runtime crash mid-call that yields a default/empty result; using a class builder object that was never fully initialized on the runtime side.","solutions":["Verify the baml Go module version matches the installed BAML CLI/runtime version and upgrade both together (`go get -u github.com/boundaryml/baml/...` + `baml version`).","Check runtime logs for an earlier panic or error in the `list_properties` method that would have made CallMethod return a non-pointer result.","Rebuild/reinstall the BAML runtime artifacts so the FFI bindings are in sync, then retry.","If it persists, file a bug with the %T value printed in the error message so maintainers can see which type leaked through the FFI layer."],"exampleFix":"// before\nrawObjects, ok := result.([]raw_objects.RawPointer)\nif !ok {\n    return nil, fmt.Errorf(\"unexpected type for class property builders: %T\", result)\n}\n// after\ncallers cannot patch this directly; guard the call site:\nprops, err := classBuilder.ListProperties()\nif err != nil {\n    return nil, fmt.Errorf(\"ListProperties unavailable (runtime/bindings mismatch): %w\", err)\n}","handlingStrategy":"try-catch","validationCode":"// Go has no pre-call check; verify version parity instead:\n// baml.Version() == expectedRuntimeVersion (checked at startup)","typeGuard":"func isClassPropertyBuilderList(result any) bool {\n    _, ok := result.([]raw_objects.RawPointer)\n    return ok\n}","tryCatchPattern":"props, err := classBuilder.ListProperties()\nif err != nil {\n    if strings.Contains(err.Error(), \"unexpected type for class property builders\") {\n        // treat as runtime/bindings mismatch: fail fast with diagnostics\n        return nil, fmt.Errorf(\"FFI contract violation in ListProperties: %w\", err)\n    }\n    return nil, err\n}","preventionTips":["Pin the baml Go module version and BAML CLI/runtime version together in your lockfiles","Run a startup smoke test that calls ListProperties on a dummy class builder","Reinstall native runtime artifacts after every BAML upgrade"],"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"}