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

  1. Add explicit type arguments: functionName<Type>
  2. Consult builtin docs for the expected number of type arguments
  3. 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

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


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)