{"record":{"id":"c6944e0111a5786a","repo":"BoundaryML/baml","slug":"baml-fetch-as-expected-url-to-be-a-string-got","errorCode":null,"errorMessage":"baml.fetch_as: expected url to be a string, got {}","messagePattern":"baml\\.fetch_as: expected url to be a string, got (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-runtime/src/async_vm_runtime.rs","lineNumber":606,"sourceCode":"                                    &parse_as_type,\n                                    &baml_types::EvaluationContext::default(),\n                                    baml_types::StreamingMode::NonStreaming,\n                                )\n                                .unwrap();\n\n                                async move {\n                                    let response = 'res: {\n                                        let client = reqwest::Client::new();\n\n                                        let req = match &url_or_request {\n                                            BamlValue::String(url) => {\n                                                client.get(url)\n                                            }\n\n                                            // we type checked earlier, should be http request type\n                                            BamlValue::Class(name, fields) => {\n                                                let Some(BamlValue::String(url)) = fields.get(\"url\") else {\n                                                    break 'res Err(anyhow!(\n                                                        \"baml.fetch_as: expected url to be a string, got {}\",\n                                                        url_or_request\n                                                    ));\n                                                };\n\n                                                let Some(BamlValue::Enum(_, method)) = fields.get(\"method\") else {\n                                                    break 'res Err(anyhow!(\n                                                        \"baml.fetch_as: expected method to be a valid HTTP method, got {}\",\n                                                        url_or_request\n                                                    ));\n                                                };\n\n                                                let mut req = match method.as_str() {\n                                                    \"Get\" => client.get(url),\n                                                    \"Post\" => client.post(url),\n                                                    \"Put\" => client.put(url),\n                                                    \"Patch\" => client.patch(url),\n                                                    \"Delete\" => client.delete(url),","sourceCodeStart":588,"sourceCodeEnd":624,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-runtime/src/async_vm_runtime.rs#L588-L624","documentation":"When `baml.fetch_as` receives a baml.HttpRequest class, it reads the `url` field and expects it to be a string. The field was missing or held a non-string value, so the HTTP request cannot be built. (The message prints the whole request object, not the offending field.)","triggerScenarios":"Constructing baml.HttpRequest without a `url` field, or with a url that is not a string (e.g. an int, null, or a nested object).","commonSituations":"Typos like `uri:` instead of `url:`, building the request dynamically where the url variable is null/undefined at runtime, or deserializing a request from JSON that lacks the url field.","solutions":["Add a `url` string field to the baml.HttpRequest constructor","Ensure the url variable is a string (coerce/interpolate it) before building the request","Fix field-name typos (`url` exactly, not `uri` or `endpoint`)"],"exampleFix":"// before (BAML)\nlet req = baml.HttpRequest{method: \"Get\", url: null}\n// after\nlet req = baml.HttpRequest{method: \"Get\", url: \"https://api.example.com/data\"}","handlingStrategy":"validation","validationCode":"function validateHttpRequest(req) {\n  if (!req || typeof req !== 'object') throw new Error('HttpRequest required');\n  if (typeof req.url !== 'string' || req.url.length === 0) throw new Error('HttpRequest.url must be a non-empty string, got: ' + JSON.stringify(req.url));\n}","typeGuard":"function hasStringUrl(req) {\n  return typeof req === 'object' && req !== null && typeof req.url === 'string' && req.url.length > 0;\n}","tryCatchPattern":"try {\n  const data = await runtime.callFunction(fnName, args);\n} catch (e) {\n  if (String(e).includes('expected url to be a string')) {\n    // inspect the baml.HttpRequest construction site and fix the url field\n  } else throw e;\n}","preventionTips":["Always set `url` explicitly as a string on baml.HttpRequest","Check for null/undefined url variables at construction time","Use the field name `url`, not `uri` or `endpoint`"],"tags":["baml","http","type-mismatch","httprequest"],"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"}