{"record":{"id":"c23a4a6010908bc1","repo":"BoundaryML/baml","slug":"expected-2-arguments-for-baml-fetch-as-got","errorCode":null,"errorMessage":"expected 2 arguments for `baml.fetch_as`, got {}","messagePattern":"expected 2 arguments for `baml\\.fetch_as`, got (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-runtime/src/async_vm_runtime.rs","lineNumber":532,"sourceCode":"                            // basically turns Rust futures into JavaScript promises,\n                            // which are supposed to be single threaded. So, on WASM,\n                            // except for compilation required types, spawn and\n                            // spawn_local are essentially equivalent.\n                            #[cfg(target_arch = \"wasm32\")]\n                            wasm_bindgen_futures::spawn_local(future);\n                        }\n\n                        baml_vm::FutureKind::Net => {\n                            // Only `baml.fetch_as` is supported for now.\n                            if pending_future.function != \"baml.fetch_as\" {\n                                break 'mainloop Err(anyhow!(\n                                    \"unkown function: {}\",\n                                    pending_future.function\n                                ));\n                            }\n\n                            if pending_future.args.len() != 2 {\n                                break 'mainloop Err(anyhow!(\n                                    \"expected 2 arguments for `baml.fetch_as`, got {}\",\n                                    pending_future.args.len()\n                                ));\n                            }\n\n                            let url_or_request =\n                                match try_baml_value_from_vm_value(&vm, &pending_future.args[0]) {\n                                    Ok(url_or_request) => url_or_request,\n                                    Err(e) => {\n                                        break 'mainloop Err(e.context(\n                                        \"baml.fetch_as: failed to get url or request from VM value\",\n                                    ));\n                                    }\n                                };\n\n                            match &url_or_request {\n                                BamlValue::String(_) => {} // Ok,\n","sourceCodeStart":514,"sourceCodeEnd":550,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-runtime/src/async_vm_runtime.rs#L514-L550","documentation":"`baml.fetch_as` takes exactly two arguments — the URL/HttpRequest value and the BAML type to parse the response as. The VM found a different argument count and aborts the main loop before executing the request.","triggerScenarios":"Calling `baml.fetch_as` with fewer than 2 args (missing the target type or the URL) or more than 2 (extra params such as headers passed positionally instead of in an HttpRequest).","commonSituations":"Forgetting the second type argument (`baml.fetch_as(url)`), passing options as extra positional args, or a code generator / transpiler emitting a wrong call arity.","solutions":["Pass exactly two arguments: the URL (or baml.HttpRequest) and the BAML type to parse as","If you need headers/body/method, build a baml.HttpRequest class and pass it as the single first argument instead of extra positional args","Count arguments in the .baml call site; fix any missing or extra ones"],"exampleFix":"// before (BAML)\nlet data = baml.fetch_as(\"https://api.example.com/data\", MyType, {headers: {\"x-a\": \"1\"}})\n// after\nlet req = baml.HttpRequest{url: \"https://api.example.com/data\", headers: {\"x-a\": \"1\"}}\nlet data = baml.fetch_as(req, MyType)","handlingStrategy":"validation","validationCode":"// ensure baml.fetch_as call sites have exactly 2 arguments\nfunction validateFetchAsArity(bamlSrc) {\n  const re = /baml\\.fetch_as\\s*\\(([^()]*)\\)/g;\n  for (const m of bamlSrc.matchAll(re)) {\n    const argc = m[1].split(',').filter(a => a.trim() !== '').length;\n    if (argc !== 2) throw new Error(`baml.fetch_as needs exactly 2 args, found ${argc}: ${m[0]}`);\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  const result = await runtime.callFunction(fnName, args);\n} catch (e) {\n  if (/expected 2 arguments for `baml.fetch_as`/.test(String(e))) {\n    // fix call site arity in .baml source and retry\n  } else throw e;\n}","preventionTips":["Always pass both a URL/request and a target type to baml.fetch_as","Pass request options via baml.HttpRequest fields, not extra positional arguments"],"tags":["baml","vm","argument-count","fetch"],"backgroundTag":"missing-required-argument","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}