{"record":{"id":"1b5ffe57fed729f9","repo":"BoundaryML/baml","slug":"baml-fetch-as-expects-a-string-url-argument-at","errorCode":null,"errorMessage":"baml.fetch_as expects a string URL argument at {:?}","messagePattern":"baml\\.fetch_as expects a string URL argument at (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-compiler/src/thir/interpret.rs","lineNumber":2752,"sourceCode":"        \"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 {\n                bail!(\n                    \"baml.fetch_as expects 1 type argument, got {} at {:?}\",\n                    type_args.len(),\n                    meta.0\n                );\n            }\n\n            let url = match &args[0] {\n                BamlValueWithMeta::String(s, _) => s.clone(),\n                _ => bail!(\n                    \"baml.fetch_as expects a string URL argument at {:?}\",\n                    meta.0\n                ),\n            };\n\n            let target_type = &type_args[0];\n\n            // Make HTTP request\n            let response = reqwest::get(&url).await.with_context(|| {\n                format!(\n                    \"baml.fetch_as: failed to fetch URL '{}' at {:?}\",\n                    url, meta.0\n                )\n            })?;\n\n            let status = response.status();\n            if !status.is_success() {\n                let body = response","sourceCodeStart":2734,"sourceCodeEnd":2770,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-compiler/src/thir/interpret.rs#L2734-L2770","documentation":"After checking arity, baml.fetch_as validates that its single argument is a string URL. The interpreter throws this when the first argument evaluates to any non-string BamlValue (int, object, list, etc.).","triggerScenarios":"Calling baml.fetch_as::<T>(x) where x evaluates to a non-string value, e.g. an int, a field of a map, or the result of a non-string expression.","commonSituations":"Passing a URL stored in a non-string variable; forgetting to interpolate into a string; passing a parsed JSON object instead of the URL string field within it.","solutions":["Ensure the first argument is a string literal or an expression evaluating to a string","Coerce or extract the URL, e.g. pass obj.url instead of obj","Inspect the value at the reported span and add an explicit string construction"],"exampleFix":"// before\nbaml.fetch_as::<MyType>(config.endpoint_port)\n// after\nbaml.fetch_as::<MyType>(\"https://example.com/endpoint\")","handlingStrategy":"type-guard","validationCode":"fn ensure_string_url(args: &[BamlValueWithMeta<ExprMetadata>]) -> Result<String, String> {\n    match args.first() {\n        Some(BamlValueWithMeta::String(s, _)) => Ok(s.clone()),\n        _ => Err(\"baml.fetch_as first argument must be a string URL\".into()),\n    }\n}","typeGuard":"fn is_string(v: &BamlValueWithMeta<ExprMetadata>) -> bool {\n    matches!(v, BamlValueWithMeta::String(_, _))\n}","tryCatchPattern":null,"preventionTips":["Keep URLs in explicitly typed string variables","Interpolate dynamic parts into a string literal instead of passing raw values","Add pre-evaluation checks that the URL argument is a string"],"tags":["baml","type-mismatch","string","builtin-function"],"backgroundTag":"type-mismatch","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"}