BoundaryML/baml · error

script body has `--function` without a value

Error message

script body has `--function` without a value

What it means

Parse guard for script bodies in baml.toml [scripts]: the token `--function` appeared as the last token of the body, so the expected function name after it is missing. V1 script bodies only accept the shape `[--function <name>] [-- <target-args>...]`; a dangling flag means the value was forgotten or misplaced.

Solutions

  1. Provide the function name after `--function`, e.g. `--function MyFunction`
  2. If the function name contains `--`, keep it after the `--` separator for target args
  3. Validate the script body before invoking

Example fix

// before
["--function"]
// after
["--function", "ExtractResume"]
Defensive patterns

Strategy: validation

Validate before calling

function validateScriptBody(tokens) {
  const i = tokens.indexOf('--function');
  if (i !== -1 && (i + 1 >= tokens.length || tokens[i + 1].startsWith('--') && tokens[i + 1] !== '--')) {
    throw new Error('--function requires a name value');
  }
}

Try / catch

try { await baml.run(scriptBody); } catch (e) { if (String(e).includes('`--function` without a value')) { console.error('Usage: [--function <name>] [-- <target-args>...]'); } else throw e; }

Prevention

When it happens

Trigger: Calling `parse_script_body` with a token list where `--function` is the last token, e.g. a script body of `"--function"` with nothing after it.

Common situations: Hand-written script bodies missing the function name; shell scripts that dropped an argument; copy-paste truncation of a `baml run` invocation.

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

Appendix: source

Thrown at baml_language/crates/baml_cli/src/run_command.rs:110

        }
        if after_separator {
            extra_args.push(token.to_string());
            i += 1;
            continue;
        }

        // Pre-separator: only `--function <value>` is recognized as a
        // run-verb flag inside a script body in v1. Other run-verb flags
        // (`--json-args`, `--include-generated`, etc.) are deliberately rejected
        // here rather than silently dropped — the toml loader is the
        // last chance to surface a typo before the script runs.
        if token == "--function" {
            i += 1;
            if i < tokens.len() {
                function = Some(tokens[i].clone());
                i += 1;
            } else {
                anyhow::bail!("script body has `--function` without a value");
            }
            continue;
        }

        if let Some(stripped) = token.strip_prefix("--") {
            anyhow::bail!(
                "unknown run-verb flag `--{stripped}` in script body. \
                 Only `--function <name>` is recognized before `--`; \
                 put target arguments after `--`."
            );
        }

        anyhow::bail!(
            "unexpected token `{token}` in script body. \
             Script bodies have the shape `[--function <name>] [-- <target-args>...]`."
        );
    }

View on GitHub (pinned to bd85ce9dee)