{"record":{"id":"3ca91e444de3c036","repo":"BoundaryML/baml","slug":"unexpected-type-for-usage-t-rawobjects-function-log","errorCode":null,"errorMessage":"unexpected type for usage: %T","messagePattern":"unexpected type for usage: %T","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/language_client_go/pkg/rawobjects_function_log.go","lineNumber":91,"sourceCode":"\t}\n\n\ttiming, ok := result.(Timing)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"unexpected type for timing: %T\", result)\n\t}\n\n\treturn timing, nil\n}\n\nfunc (f *functionLog) Usage() (Usage, error) {\n\tresult, err := raw_objects.CallMethod(f, \"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 (f *functionLog) RawLLMResponse() (string, error) {\n\tresult, err := raw_objects.CallMethod(f, \"raw_llm_response\", nil)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to get raw LLM response: %w\", err)\n\t}\n\n\tresponse, ok := result.(string)\n\tif !ok {\n\t\treturn \"\", fmt.Errorf(\"unexpected type for raw LLM response: %T\", result)\n\t}\n\n\treturn response, nil\n}","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_go/pkg/rawobjects_function_log.go#L73-L109","documentation":"Returned by Usage() when the 'usage' call succeeded but the decoded value failed the `result.(Usage)` assertion — the runtime handed back a Go value of an unexpected concrete type. This is an FFI contract guard indicating a client/runtime representation mismatch, a decoder bug, or object corruption; it is not caused by user input.","triggerScenarios":"usage decodes into a non-Usage raw object variant; version skew between the BAML runtime and the generated Go client; stale/freed functionLog objects yielding garbage decodes.","commonSituations":"Newer engine with older generated client (field representation changed); logs consumed after stream teardown; decodeObjectResponse returning the wrong variant.","solutions":["Regenerate the Go client (`baml generate`) to match the installed runtime.","Read the %T value in the error to identify the actual returned type.","Consume the FunctionLog while its owning stream is still valid.","Report upstream with versions and the printed type if it happens on a fresh object."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"if fnLog == nil {\n    return errors.New(\"function log is nil; cannot read Usage\")\n}","typeGuard":"func usageIsUsage(v any) bool {\n    _, ok := v.(Usage)\n    return ok\n}","tryCatchPattern":"usage, err := fnLog.Usage()\nif err != nil {\n    if strings.Contains(err.Error(), \"unexpected type for usage:\") {\n        return nil, fmt.Errorf(\"usage object contract mismatch (version skew?): %w\", err)\n    }\n    return nil, err\n}","preventionTips":["Keep generated client and BAML runtime versions aligned.","Record the %T value from the error for bug reports.","Consume the log while its stream is live.","Pin client/runtime versions in your lockfile."],"tags":["go","ffi","type-mismatch","baml"],"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"}