BoundaryML/baml · error
startsWith() method takes exactly 1 argument at
Error message
startsWith() method takes exactly 1 argument at {:?} What it means
THIR interpreter runtime error: `startsWith()` was invoked with an argument count other than exactly one. The method takes a single string prefix argument; zero or multiple arguments fail the arity check at evaluation time.
Solutions
- Pass exactly one string argument: `s.startsWith(prefix)`.
- If a positional check is needed, slice the string first (e.g. via substring-style operations) or move the logic to the host language.
- Verify the intended method and its arity against BAML's string method set.
Example fix
// before
let ok = path.startsWith("/api", 4);
// after
let ok = path.startsWith("/api"); Defensive patterns
Strategy: validation
Validate before calling
const call = src.match(/\.startsWith\s*\(([^)]*)\)/);
if (call && call[1].split(',').filter(a => a.trim()).length !== 1) {
throw new Error('startsWith() takes exactly 1 argument: ' + call[0]);
} Try / catch
try {
const res = await b.Function(args);
} catch (e) {
if (String(e.message).includes('startsWith() method takes exactly 1 argument')) {
// fix the arity at the reported span and re-run
}
throw e;
} Prevention
- Drop JS-style position arguments — BAML's startsWith() takes one argument only.
- For offset prefix checks, slice the string first.
- Lint BAML sources for startsWith() calls with zero or multiple arguments.
When it happens
Trigger: Calling `s.startsWith()` with no argument, or with multiple arguments — BAML's startsWith has no position/offset parameter unlike JavaScript's String.prototype.startsWith.
Common situations: Porting JavaScript code using `s.startsWith(prefix, position)` and keeping the second argument; omitting the argument when translating from a different prefix-check 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
- includes() method takes exactly 1 argument at
- toUpperCase() method takes no arguments at
- trim() method takes no arguments at
- includes() argument must be a string at
- includes() method only available on strings at
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/f681a0f4409a7449.
Report an issue: GitHub.
Appendix: source
Thrown at engine/baml-compiler/src/thir/interpret.rs:2897
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!(
"startsWith() method takes exactly 1 argument at {:?}",
meta.0
);
}
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
);View on GitHub (pinned to bd85ce9dee)