BoundaryML/baml · error

split() method takes exactly 1 argument at

Error message

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

What it means

The split method requires exactly one argument (the delimiter). If a call passes zero arguments or more than one, the interpreter bails with this message. The library enforces the fixed signature split(delimiter).

Solutions

  1. Provide exactly one string delimiter: s.split(",").
  2. If you need a max-parts behavior, post-process the result (e.g. rejoin and split again) instead of passing a second argument.
  3. Remove any extra arguments at the failing call site.

Example fix

// before
let parts = s.split(",", 3);

// after
let parts = s.split(",");
Defensive patterns

Strategy: validation

Validate before calling

// split takes exactly one string delimiter argument
let args_ok = args.len() == 1;

Try / catch

match result {
  Err(e) if e.to_string().contains("takes exactly 1 argument") => log_missing_arg("split"),
  other => other,
}

Prevention

When it happens

Trigger: Calling s.split() with no delimiter, or s.split(",", 3) with an extra limit argument, in BAML expression code.

Common situations: Porting code from languages where split accepts an optional limit or regex; omitting the delimiter assuming a default whitespace split; dynamic argument arrays with an extra element.

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/67653751c5a860e9. Report an issue: GitHub.

Appendix: source

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

                );
            };
            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);
            };
            let parts: Vec<BamlValueWithMeta<ExprMetadata>> = s
                .split(delimiter.as_str())
                .map(|part| BamlValueWithMeta::String(part.to_string(), meta.clone()))
                .collect();
            Ok(BamlValueWithMeta::List(parts, meta.clone()))
        }
        "substring" => {
            let BamlValueWithMeta::String(s, _) = receiver else {
                bail!(
                    "substring() method only available on strings at {:?}",
                    meta.0
                );
            };
            if args.len() != 2 {

View on GitHub (pinned to bd85ce9dee)