BoundaryML/baml · error
baml.fetch_as expects 1 type argument, got
Error message
baml.fetch_as expects 1 type argument, got {} at {:?} What it means
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.
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
Example fix
// before let v = baml.fetch_as(url) // after let v = baml.fetch_as::<MyType>(url)
Defensive patterns
Strategy: validation
Validate before calling
fn validate_fetch_as_type_args(type_args: &[Type]) -> Result<(), String> {
if type_args.len() != 1 {
return Err(format!("baml.fetch_as needs exactly 1 type argument, got {}", type_args.len()));
}
Ok(())
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- unknown builtin function
- array assignment index out of bounds
- array assignment on non-list value at
- array assignment requires a non-negative integer index at
- assign to undeclared variable
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/ccc0e897de3caec1.
Report an issue: GitHub.
Appendix: source
Thrown at engine/baml-compiler/src/thir/interpret.rs:2743
"baml.media.image.from_url expects a string argument at {:?}",
meta.0
),
};
Ok(BamlValueWithMeta::Media(
baml_types::BamlMedia::url(baml_types::BamlMediaType::Image, url, None),
meta.clone(),
))
}
"baml.fetch_as" => {
if args.len() != 1 {
bail!(
"baml.fetch_as expects 1 argument (url), got {} at {:?}",
args.len(),
meta.0
);
}
if type_args.len() != 1 {
bail!(
"baml.fetch_as expects 1 type argument, got {} at {:?}",
type_args.len(),
meta.0
);
}
let url = match &args[0] {
BamlValueWithMeta::String(s, _) => s.clone(),
_ => bail!(
"baml.fetch_as expects a string URL argument at {:?}",
meta.0
),
};
let target_type = &type_args[0];
// Make HTTP request
let response = reqwest::get(&url).await.with_context(|| {View on GitHub (pinned to bd85ce9dee)