BoundaryML/baml · error
arity mismatch: expected
Error message
arity mismatch: expected {} args, got {} What it means
The interpreter compares the resolved callee's declared arity with the number of arguments supplied at the call site and throws "arity mismatch: expected {} args, got {}" when they differ. BAML functions have fixed parameter counts enforced at interpretation time.
Solutions
- Read the expected count from the message and adjust the call site to pass exactly that many arguments
- Check the function's signature for recently added/removed parameters and update all callers
- For optional parameters, pass explicit defaults rather than omitting them
- If the function is generated, regenerate/refresh definitions so signatures match
Example fix
// before
fn add(a, b) { a + b }
add(1) // arity mismatch: expected 2 args, got 1
// after
add(1, 2) Defensive patterns
Strategy: validation
Validate before calling
// Validate argument count against the function signature before invoking
function checkArity(signatureParams: number, args: unknown[]): void {
if (args.length !== signatureParams)
throw new Error(`Call needs ${signatureParams} args, got ${args.length}`);
} Try / catch
try {
return fn(...args);
} catch (e) {
if (String(e).startsWith("arity mismatch")) {
console.error(String(e), "— update this call site to match the function signature");
}
throw e;
} Prevention
- Update all call sites whenever a function signature changes (use project-wide search)
- Use the LSP's find-references to locate callers of changed functions
- Prefer explicit parameters over growing positional argument lists
- Run type checking / tests on .baml files in CI before deploying
When it happens
Trigger: Calling a BAML function with more or fewer positional arguments than its signature declares, during evaluate_expr_with_context call handling.
Common situations: Adding a parameter to a function but not updating all call sites; copy-pasting a call from an older version of a function signature; calling generated/__LLM_FUNCTION__ functions with the wrong argument count.
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
- Filter function ' ' must take exactly 1 parameter (current…
- push() expects exactly one argument at
- array access on non-list at
- array assignment index out of bounds
- array assignment on non-list value at
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/bb8bb70d53e87df9.
Report an issue: GitHub.
Appendix: source
Thrown at engine/baml-compiler/src/thir/interpret.rs:1880
thir,
run_llm_function,
watch_handler,
function_name,
)
.await?,
)?);
}
// Handle builtin functions
let result =
evaluate_builtin_function(&fn_name, &arg_vals, type_args, &meta)
.await?;
return Ok(EvalValue::Value(result));
}
}
if arity != args.len() {
bail!(
"arity mismatch: expected {} args, got {}",
arity,
args.len()
);
}
// Evaluate arguments first
let mut arg_vals: Vec<BamlValueWithMeta<ExprMetadata>> =
Vec::with_capacity(args.len());
for a in args.iter() {
arg_vals.push(expect_value(
evaluate_expr(
a,
scopes,
thir,
run_llm_function,
watch_handler,
function_name,View on GitHub (pinned to bd85ce9dee)