{"record":{"id":"ccc0e897de3caec1","repo":"BoundaryML/baml","slug":"baml-fetch-as-expects-1-type-argument-got-at","errorCode":null,"errorMessage":"baml.fetch_as expects 1 type argument, got {} at {:?}","messagePattern":"baml\\.fetch_as expects 1 type argument, got (.+?) at (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-compiler/src/thir/interpret.rs","lineNumber":2743,"sourceCode":"                    \"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 {\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(|| {","sourceCodeStart":2725,"sourceCodeEnd":2761,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-compiler/src/thir/interpret.rs#L2725-L2761","documentation":"baml.fetch_as is a builtin function in the BAML interpreter that fetches a URL and parses the response JSON into a specified type. It requires exactly one type argument (the target type) supplied via generics/apply. The compiler throws this error at interpretation time when the call site supplies a number of type arguments other than one.","triggerScenarios":"Calling baml.fetch_as(url) with zero type arguments, or with two or more type arguments (e.g. baml.fetch_as::<A, B>(url)) inside a BAML expression evaluated by evaluate_builtin_function.","commonSituations":"Forgetting to annotate the target type when writing a fetch expression; copying a fetch_as call from an example with multiple generic params; a refactor that changed the target type but left a stale second type argument.","solutions":["Supply exactly one type argument to baml.fetch_as naming the target type, e.g. baml.fetch_as::<MyType>(url)","Check the BAML source at the span reported in the error (the meta location) to find the offending call","Simplify: if you need multiple shapes, use two separate fetch_as calls, each with one type argument"],"exampleFix":"// before\nlet v = baml.fetch_as(url)\n// after\nlet v = baml.fetch_as::<MyType>(url)","handlingStrategy":"validation","validationCode":"fn validate_fetch_as_type_args(type_args: &[Type]) -> Result<(), String> {\n    if type_args.len() != 1 {\n        return Err(format!(\"baml.fetch_as needs exactly 1 type argument, got {}\", type_args.len()));\n    }\n    Ok(())\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always annotate the target type at fetch_as call sites","Use editor/LSP checks on BAML expressions to catch arity issues early","Review generated fetch_as calls after refactors"],"tags":["baml","type-arguments","builtin-function","interpreter"],"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"}