BoundaryML/baml · error

trim() method takes no arguments at

Error message

trim() method takes no arguments at {:?}

What it means

THIR interpreter runtime error: `trim()` was invoked with arguments. Like the other string methods, trim takes none, so extra arguments indicate a malformed call and evaluation bails at the method-call site.

Solutions

  1. Call trim() with no arguments: `s.trim()`.
  2. If trimming a specific character is needed, use replace-style operations or handle it in the host language before the value enters BAML.
  3. Verify the method name — includes()/startsWith() take one argument; trim does not.

Example fix

// before
let clean = input.trim("\n");
// after
let clean = input.trim();
Defensive patterns

Strategy: validation

Validate before calling

const bad = src.match(/\.trim\s*\(\s*[^)]+/);
if (bad) throw new Error('trim() takes no arguments: ' + bad[0]);

Try / catch

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

Prevention

When it happens

Trigger: Writing `s.trim(charset)` or `s.trim(anything)` in a BAML expression — BAML does not support trimming a specific character set via arguments.

Common situations: Devs coming from Rust's trim_matches or other trim-with-set APIs pass a character/pattern argument; attempting to trim a specific character like a trailing newline by passing "\n".

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

Appendix: source

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

        }
        "toUpperCase" => {
            let BamlValueWithMeta::String(s, _) = receiver else {
                bail!(
                    "toUpperCase() method only available on strings at {:?}",
                    meta.0
                );
            };
            if !args.is_empty() {
                bail!("toUpperCase() method takes no arguments at {:?}", meta.0);
            }
            Ok(BamlValueWithMeta::String(s.to_uppercase(), meta.clone()))
        }
        "trim" => {
            let BamlValueWithMeta::String(s, _) = receiver else {
                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);

View on GitHub (pinned to bd85ce9dee)