BoundaryML/baml · error

includes() method takes exactly 1 argument at

Error message

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

What it means

THIR interpreter runtime error: the `includes()` string method was invoked with an argument count other than exactly one (zero or multiple). includes takes a single string search argument; the arity check fails before any containment test runs.

Solutions

  1. Pass exactly one string argument: `s.includes(search)`.
  2. If a start-position search is needed, slice the string first or move the logic to the host language.
  3. Confirm the method name and intended argument count against the BAML string method surface.

Example fix

// before
let has = text.includes("key", 10);
// after
let has = text.slice(10).includes("key");  // or drop the offset
Defensive patterns

Strategy: validation

Validate before calling

const call = src.match(/\.includes\s*\(([^)]*)\)/);
if (call && call[1].split(',').filter(a => a.trim()).length !== 1) {
  throw new Error('includes() takes exactly 1 argument: ' + call[0]);
}

Try / catch

try {
  const res = await b.Function(args);
} catch (e) {
  if (String(e.message).includes('includes() method takes exactly 1 argument')) {
    // fix arity at the reported span and re-run
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling `s.includes()` with no argument, or `s.includes(a, b)` with multiple arguments — BAML's includes does not support a start-position parameter like JavaScript's String.prototype.includes.

Common situations: Porting JavaScript code that uses `s.includes(sub, fromIndex)` and keeping the second argument; forgetting the argument entirely when converting from a different containment API.

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

Appendix: source

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

                bail!("trim() method only available on strings at {:?}", meta.0);
            };
            if !args.is_empty() {
                bail!("trim() method takes no arguments at {:?}", meta.0);
            }
            Ok(BamlValueWithMeta::String(
                s.trim().to_string(),
                meta.clone(),
            ))
        }
        "includes" => {
            let BamlValueWithMeta::String(s, _) = receiver else {
                bail!(
                    "includes() method only available on strings at {:?}",
                    meta.0
                );
            };
            if args.len() != 1 {
                bail!("includes() method takes exactly 1 argument at {:?}", meta.0);
            }
            let BamlValueWithMeta::String(search, _) = &args[0] else {
                bail!("includes() argument must be a string at {:?}", meta.0);
            };
            Ok(BamlValueWithMeta::Bool(
                s.contains(search.as_str()),
                meta.clone(),
            ))
        }
        "startsWith" => {
            let BamlValueWithMeta::String(s, _) = receiver else {
                bail!(
                    "startsWith() method only available on strings at {:?}",
                    meta.0
                );
            };
            if args.len() != 1 {
                bail!(

View on GitHub (pinned to bd85ce9dee)