{"record":{"id":"0e790b3e4ede2ab9","repo":"BoundaryML/baml","slug":"unexpected-type-for-media-creation-t","errorCode":null,"errorMessage":"unexpected type for media creation: %T","messagePattern":"unexpected type for media creation: %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/language_client_go/pkg/rawobjects_constructors.go","lineNumber":49,"sourceCode":"}\n\nfunc (r *BamlRuntime) newMediaFromUrl(mediaType MediaType, url string, mimeType *string) (media, error) {\n\tkwargs, err := serde.EncodeMapEntries(map[string]any{\n\t\t\"mime_type\": mimeType,\n\t\t\"url\":       url,\n\t}, \"media constructor args\")\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to encode kwargs: %w\", err)\n\t}\n\n\tptr, err := raw_objects.NewRawObject(r.runtime, mediaType.objectType(), kwargs)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to create media: %w\", err)\n\t}\n\n\tas_media, ok := ptr.(media)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"unexpected type for media creation: %T\", ptr)\n\t}\n\n\treturn as_media, nil\n}\n\nfunc (r *BamlRuntime) NewImageFromUrl(url string, mimeType *string) (Image, error) {\n\treturn r.newMediaFromUrl(MediaType_Image, url, mimeType)\n}\n\nfunc (r *BamlRuntime) NewAudioFromUrl(url string, mimeType *string) (Audio, error) {\n\treturn r.newMediaFromUrl(MediaType_Audio, url, mimeType)\n}\n\nfunc (r *BamlRuntime) NewPDFFromUrl(url string, mimeType *string) (PDF, error) {\n\treturn r.newMediaFromUrl(MediaType_PDF, url, mimeType)\n}\n\nfunc (r *BamlRuntime) NewVideoFromUrl(url string, mimeType *string) (Video, error) {","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_go/pkg/rawobjects_constructors.go#L31-L67","documentation":"After NewRawObject succeeds, newMediaFromUrl asserts the returned value implements the media interface. If it does not, this error is thrown. Like the collector variant, it is an internal consistency check indicating the cffi runtime returned an object of an unexpected type for the requested media type.","triggerScenarios":"Calling any of the New*FromUrl constructors when the runtime returns a value that does not satisfy the media interface — a bindings/runtime version mismatch or a NewRawObject dispatch bug, not a caller-input problem.","commonSituations":"Partial SDK upgrades leaving the Go wrapper types out of sync with the native library; custom or patched engine builds that return different wrapper types for media objects.","solutions":["Align the Go SDK module and native BAML runtime to the same release version; run `go mod tidy` and reinstall","Rebuild or re-download the native runtime binary","Read the %T value in the message to identify which wrong type was returned and report upstream if reproducible on a clean install"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":"func asMedia(v any) (media, bool) {\n    m, ok := v.(media)\n    return m, ok\n}","tryCatchPattern":"img, err := runtime.NewImageFromUrl(u, mime)\nif err != nil {\n    if strings.Contains(err.Error(), \"unexpected type for media creation\") {\n        return nil, fmt.Errorf(\"baml runtime/bindings out of sync: %w\", err)\n    }\n    return nil, err\n}","preventionTips":["Upgrade the baml module and native runtime atomically","Fail fast with a startup media-construction smoke test","Report the %T value from the message when filing bugs"],"tags":["go","baml-runtime","type-assertion","internal"],"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-14T11:17:12.474Z"}