{"record":{"id":"a196186c4402b760","repo":"BoundaryML/baml","slug":"unexpected-type-for-usage-t","errorCode":null,"errorMessage":"unexpected type for usage: %T","messagePattern":"unexpected type for usage: %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/language_client_go/pkg/rawobjects_collector.go","lineNumber":35,"sourceCode":"}\n\nfunc (c *collector) ObjectType() cffi.BamlObjectType {\n\treturn cffi.BamlObjectType_OBJECT_COLLECTOR\n}\n\nfunc (c *collector) pointer() int64 {\n\treturn c.RawObject.Pointer()\n}\n\nfunc (c *collector) Usage() (Usage, error) {\n\tresult, err := raw_objects.CallMethod(c, \"usage\", nil)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to get usage: %w\", err)\n\t}\n\n\tusage, ok := result.(Usage)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"unexpected type for usage: %T\", result)\n\t}\n\n\treturn usage, nil\n}\n\nfunc (c *collector) Name() (string, error) {\n\tresult, err := raw_objects.CallMethod(c, \"name\", nil)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to get name: %w\", err)\n\t}\n\n\tname, ok := result.(string)\n\tif !ok {\n\t\treturn \"\", fmt.Errorf(\"unexpected type for name: %T\", result)\n\t}\n\n\treturn name, nil\n}","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_go/pkg/rawobjects_collector.go#L17-L53","documentation":"After Collector.Usage() successfully calls the runtime's `usage` method, it asserts the decoded result implements the Usage interface. If the FFI layer returns any other Go type, this error is thrown. The method call itself succeeded, but the returned payload did not match the documented Usage shape — a contract violation between the native runtime and the Go bindings.","triggerScenarios":"Calling collector.Usage() when the runtime returns a non-Usage value: a raw pointer typed as a different object, nil from a degraded runtime response, or a result decoded with the wrong object type tag.","commonSituations":"Version drift between the Go module and the native BAML runtime changing the usage object's type tag; runtime-side partial failure producing a placeholder object; a collector created by a different runtime instance.","solutions":["Match Go binding and BAML runtime versions exactly; upgrade/reinstall both together.","Check whether the underlying collector still tracks active calls; a usage object may only exist after at least one tracked call.","Recreate the collector and retry to rule out corrupt runtime state.","Report the printed %T type to BAML maintainers if it reproduces on matched versions."],"exampleFix":"// before\nusage, err := collector.Usage()\nif err != nil { panic(err) }\n// after\nusage, err := collector.Usage()\nif err != nil {\n    return nil, fmt.Errorf(\"usage shape unexpected, verify baml version parity: %w\", err)\n}","handlingStrategy":"type-guard","validationCode":"// Only call Usage after at least one tracked call:\n// if callCount == 0 { return nil, errors.New(\"no tracked calls yet\") }","typeGuard":"func isUsage(result any) bool {\n    _, ok := result.(Usage)\n    return ok\n}","tryCatchPattern":"usage, err := collector.Usage()\nif err != nil {\n    if strings.Contains(err.Error(), \"unexpected type for usage\") {\n        return nil, fmt.Errorf(\"usage payload shape violated (check version parity): %w\", err)\n    }\n    return nil, err\n}","preventionTips":["Pin Go bindings and runtime to the same version","Ensure at least one LLM call has been tracked before reading usage","Avoid caching Usage objects across runtime restarts"],"tags":["go","ffi","type-assertion","collector"],"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"}