BoundaryML/baml · error

endsWith() method takes exactly 1 argument at

Error message

endsWith() method takes exactly 1 argument at {:?}

What it means

When the interpreter handles the "endsWith" string method it requires exactly one argument (the suffix to test). If the call site passed zero or multiple arguments, it bails with this message before evaluating anything. The library enforces the fixed arity of endsWith(suffix).

Solutions

  1. Pass exactly one string argument: s.endsWith(suffix).
  2. If you intended multiple suffixes, call endsWith once per suffix and combine with ||.
  3. Count the arguments at the failing call site and remove extras or supply the missing suffix.

Example fix

// before
let ok = s.endsWith("a", "b");

// after
let ok = s.endsWith("a") || s.endsWith("b");
Defensive patterns

Strategy: validation

Validate before calling

// assert arity before calling
// endsWith takes exactly 1 argument
let args_ok = args.len() == 1;

Try / catch

// catch and report arity problems
match result {
  Err(e) if e.to_string().contains("takes exactly 1 argument") => log_missing_arg("endsWith"),
  other => other,
}

Prevention

When it happens

Trigger: Calling str.endsWith() with no arguments, or str.endsWith("a", "b") with more than one argument, inside a BAML expression evaluated by evaluate_method_call.

Common situations: Copying split/substring-style multi-argument calling conventions to endsWith; concatenating argument lists dynamically and accidentally passing an extra element; forgetting the suffix argument entirely.

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/1b41ccc8596f4510. Report an issue: GitHub.

Appendix: source

Thrown at engine/baml-compiler/src/thir/interpret.rs:2918

                );
            }
            let BamlValueWithMeta::String(prefix, _) = &args[0] else {
                bail!("startsWith() argument must be a string at {:?}", meta.0);
            };
            Ok(BamlValueWithMeta::Bool(
                s.starts_with(prefix.as_str()),
                meta.clone(),
            ))
        }
        "endsWith" => {
            let BamlValueWithMeta::String(s, _) = receiver else {
                bail!(
                    "endsWith() method only available on strings at {:?}",
                    meta.0
                );
            };
            if args.len() != 1 {
                bail!("endsWith() method takes exactly 1 argument at {:?}", meta.0);
            }
            let BamlValueWithMeta::String(suffix, _) = &args[0] else {
                bail!("endsWith() argument must be a string at {:?}", meta.0);
            };
            Ok(BamlValueWithMeta::Bool(
                s.ends_with(suffix.as_str()),
                meta.clone(),
            ))
        }
        "split" => {
            let BamlValueWithMeta::String(s, _) = receiver else {
                bail!("split() method only available on strings at {:?}", meta.0);
            };
            if args.len() != 1 {
                bail!("split() method takes exactly 1 argument at {:?}", meta.0);
            }
            let BamlValueWithMeta::String(delimiter, _) = &args[0] else {
                bail!("split() argument must be a string at {:?}", meta.0);

View on GitHub (pinned to bd85ce9dee)