BoundaryML/baml · error · DatamodelError
Generic function must have a type argument. Try adding a…
Error message
Generic function {} must have a type argument. Try adding a type argument like this: {}<Type> What it means
Builtin generic functions (e.g. type-level builtins like map/filter style generics) must be instantiated with explicit type arguments. Applying a builtin identifier with an empty type_args list triggers this error with a suggested `<Type>` syntax.
Solutions
- Add explicit type arguments: functionName<Type>
- Consult builtin docs for the expected number of type arguments
- Update code to the newer generic-call syntax after BAML version upgrades
Example fix
// before let r = map(items, f) // after let r = map<string>(items, f)
Defensive patterns
Strategy: validation
Validate before calling
// Require type args on builtin generics before compiling
if is_builtin_identifier(call.name) && call.type_args.is_empty() {
bail!("builtin {} requires a <Type> argument", call.name);
} Prevention
- Always write explicit type arguments on builtin generics
- Check builtin signatures in BAML docs when upgrading versions
- Let the LSP insert generic placeholders
When it happens
Trigger: Using a builtin generic identifier in an App expression without any `<...>` type arguments, detected when is_builtin_identifier(name) && type_args.is_empty().
Common situations: Writing builtins like `map`/`filter`-style generics without their type parameter, after upgrading BAML where type arguments became mandatory for a builtin.
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
- assertion failed
- baml.errors.InvalidArgument
- baml.fetch_as: expected header key to be a valid HTTP…
- baml.fetch_as expects 1 argument (url), got
- baml.media.image.from_url expects 1 argument, got
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/9003e0f7c61168a8.
Report an issue: GitHub.
Appendix: source
Thrown at engine/baml-lib/baml-core/src/validate/validation_pipeline/validations/expr_fns.rs:309
anyhow::anyhow!("Unknown variable {}", &identifier.to_string()),
identifier.span().clone(),
));
}
}
Expression::Lambda(_args, _body, _span) => {}
Expression::App(app) => {
// Validate the function name.
if !scope.contains(app.name.name()) {
ctx.push_error(DatamodelError::new_anyhow_error(
anyhow::anyhow!("Unknown function {}", &app.name.to_string()),
app.span().clone(),
));
}
// Validate generics.
if ir::builtin::is_builtin_identifier(app.name.name()) && app.type_args.is_empty() {
ctx.push_error(DatamodelError::new_anyhow_error(
anyhow::anyhow!(
"Generic function {} must have a type argument. Try adding a type argument like this: {}<Type>",
app.name.name(),
app.name.name()
),
app.span().clone(),
));
}
for arg in &app.args {
validate_expression(ctx, arg, scope);
}
}
Expression::Array(items, _span) => {
for item in items {
validate_expression(ctx, item, scope);
}
}
Expression::Map(fields, _span) => {
for (_key, value) in fields {View on GitHub (pinned to bd85ce9dee)