BoundaryML/baml · error
length() method takes no arguments at {:?}
Error message
length() method takes no arguments at {:?} What it means
THIR interpreter runtime error: the `length()` method was invoked with one or more arguments. The builtin length method on lists, strings, and maps takes none; extra arguments mean the call site is malformed (perhaps intending a different function), and evaluation aborts with the method-call location.
Source
Thrown at engine/baml-compiler/src/thir/interpret.rs:2809
Ok(parsed_value)
}
_ => bail!("unknown builtin function '{}' at {:?}", fn_name, meta.0),
}
}
fn evaluate_method_call(
receiver: &BamlValueWithMeta<ExprMetadata>,
method_name: &str,
args: &[BamlValueWithMeta<ExprMetadata>],
meta: &ExprMetadata,
) -> Result<BamlValueWithMeta<ExprMetadata>> {
match method_name {
"length" => {
// Array/List/String/Map length method
match receiver {
BamlValueWithMeta::List(items, _) => {
if !args.is_empty() {
bail!("length() method takes no arguments at {:?}", meta.0);
}
Ok(BamlValueWithMeta::Int(items.len() as i64, meta.clone()))
}
BamlValueWithMeta::String(s, _) => {
if !args.is_empty() {
bail!("length() method takes no arguments at {:?}", meta.0);
}
Ok(BamlValueWithMeta::Int(
s.chars().count() as i64,
meta.clone(),
))
}
BamlValueWithMeta::Map(map, _) => {
if !args.is_empty() {
bail!("length() method takes no arguments at {:?}", meta.0);
}
Ok(BamlValueWithMeta::Int(map.len() as i64, meta.clone()))
}View on GitHub (pinned to bd85ce9dee)
Solutions
- Remove all arguments from the length() call
- If filtering by a predicate is intended, filter the list first, then call length()
Example fix
// before let n = items.length(0) // after let n = items.length()
Defensive patterns
Strategy: validation
Validate before calling
fn validate_length_call(args: &[BamlValueWithMeta<ExprMetadata>]) -> Result<(), String> {
if !args.is_empty() {
return Err("length() takes no arguments".into());
}
Ok(())
} Prevention
- Never pass arguments to length()
- Filter before counting if needed
- Lint generated expressions for non-empty arg lists on zero-arg methods
When it happens
Trigger: Evaluating someList.length(x) or someList.length(a, b) where someList is a BamlValueWithMeta::List.
Common situations: Confusing length() with functions in other languages that take a predicate or separator; mechanically converting len(list) style calls from Python.
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
- length() method not available on type {:?} at {:?}
- toLowerCase() method takes no arguments at {:?}
- env.get expects exactly one argument
- baml.media.image.from_url expects 1 argument, got {} at {:?}
- baml.fetch_as expects 1 argument (url), got {} at {:?}
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/ed90036d86500b9a.
Report an issue: GitHub.