{"record":{"id":"c18736817d47e354","repo":"BoundaryML/baml","slug":"baml-media-image-from-url-expects-a-string-argument-at","errorCode":null,"errorMessage":"baml.media.image.from_url expects a string argument at {:?}","messagePattern":"baml\\.media\\.image\\.from_url expects a string argument at (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-compiler/src/thir/interpret.rs","lineNumber":2724,"sourceCode":"\nasync fn evaluate_builtin_function(\n    fn_name: &str,\n    args: &[BamlValueWithMeta<ExprMetadata>],\n    type_args: &[baml_types::TypeIR],\n    meta: &ExprMetadata,\n) -> Result<BamlValueWithMeta<ExprMetadata>> {\n    match fn_name {\n        \"baml.media.image.from_url\" => {\n            if args.len() != 1 {\n                bail!(\n                    \"baml.media.image.from_url expects 1 argument, got {} at {:?}\",\n                    args.len(),\n                    meta.0\n                );\n            }\n            let url = match &args[0] {\n                BamlValueWithMeta::String(s, _) => s.clone(),\n                _ => bail!(\n                    \"baml.media.image.from_url expects a string argument at {:?}\",\n                    meta.0\n                ),\n            };\n            Ok(BamlValueWithMeta::Media(\n                baml_types::BamlMedia::url(baml_types::BamlMediaType::Image, url, None),\n                meta.clone(),\n            ))\n        }\n        \"baml.fetch_as\" => {\n            if args.len() != 1 {\n                bail!(\n                    \"baml.fetch_as expects 1 argument (url), got {} at {:?}\",\n                    args.len(),\n                    meta.0\n                );\n            }\n            if type_args.len() != 1 {","sourceCodeStart":2706,"sourceCodeEnd":2742,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-compiler/src/thir/interpret.rs#L2706-L2742","documentation":"Thrown when `baml.media.image.from_url` is called with exactly one argument, but that argument is not a String. The builtin matches the single argument against BamlValueWithMeta::String and bails on any other variant (int, media, class, null, etc.).","triggerScenarios":"Passing a non-string to baml.media.image.from_url, e.g. a previously constructed Media value, a number, or a value read from JSON that arrived typed as something other than string.","commonSituations":"Passing an existing image/media object instead of a URL string, a variable that was assigned an int ID rather than the URL, or a null when the URL field was missing from config/JSON.","solutions":["Pass the URL as a plain string: baml.media.image.from_url(\"https://...\")","If you already have a Media value, use it directly instead of re-wrapping it in from_url","Ensure the variable holding the URL is typed/annotated as string and is non-null","Validate/parse the URL source upstream so the argument is guaranteed to be a string"],"exampleFix":"// before (BAML)\nlet img = baml.media.image.from_url(existingMedia);\n// after\nlet img = existingMedia;  // or baml.media.image.from_url(\"https://example.com/img.png\")","handlingStrategy":"type-guard","validationCode":"// validate argument before calling the builtin\nif (typeof url !== 'string') {\n  throw new Error(`from_url needs a string url, got ${typeof url}`);\n}","typeGuard":"const isString = (v: unknown): v is string => typeof v === 'string';","tryCatchPattern":"try {\n  img = evaluate(call);\n} catch (e) {\n  if (String(e).includes('baml.media.image.from_url expects a string argument')) {\n    // pass url string directly or reuse existing Media value\n  }\n  throw e;\n}","preventionTips":["Never pass Media objects back into from_url; use them directly","Ensure url fields are typed string and non-null","Validate URL source values (config/JSON) before use"],"tags":["baml","builtin","type-mismatch","media"],"backgroundTag":"invalid-argument-value","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"}