BoundaryML/baml · error
positional `<TARGET>` is a function name, not a file path. F
Error message
positional `<TARGET>` is a function name, not a file path. For a single-file source, use `--file {target}` and pass the function via `-f <NAME>`. For example:
`baml run --file {target} -f <NAME>`
What it means
The positional `<TARGET>` argument of `baml run` is a function (or script) name, never a file path. When the value looks like a path (e.g. `baml_src/main.baml`), the CLI redirects the user to `--file` for single-file source and `-f <NAME>` for the function.
Source
Thrown at baml_language/crates/baml_cli/src/run_command.rs:485
if self.file.is_some() && self.target.is_none() && self.functions.is_empty() {
return self.run_single_target("main", reporter);
}
// No target → print help and exit non-zero. (Implicit `main` no
// longer exists.)
if self.target.is_none() && self.functions.is_empty() {
Self::print_run_help();
return Ok(crate::ExitCode::Other);
}
if let Some(target) = &self.target {
// Helpful redirect when the user typed a path as the
// positional (e.g. `baml run baml_src/main.baml`). Positional
// `<TARGET>` is always a function name; for a `.baml` source
// use `--file`.
if looks_like_path(target) {
anyhow::bail!(
"positional `<TARGET>` is a function name, not a file path. \
For a single-file source, use `--file {target}` and pass the \
function via `-f <NAME>`. For example:\n\
\n `baml run --file {target} -f <NAME>`\n",
);
}
return self.run_single_target(target, reporter);
}
self.run_subcommand_targets(reporter)
}
/// Positional `<TARGET>` path: one function, no subcommand layer.
/// `[scripts]` aliases are resolved here too (positional only).
fn run_single_target(&self, target: &str, reporter: &Reporter) -> Result<crate::ExitCode> {
let argv = self.build_argv_for_single(target);
let Compiled {
db,
package,View on GitHub (pinned to bd85ce9dee)
Solutions
- Pass the file via `--file` and the function name via `-f <NAME>`
- Use `baml run --file <path> -f <functionName>` instead of a positional path
- If you meant a function, pass just the function name as the positional
Example fix
// before baml run baml_src/main.baml // after baml run --file baml_src/main.baml -f MyFunction
Defensive patterns
Strategy: validation
Validate before calling
if (positional && /\.[^.\/\\]+$|\//.test(positional)) { throw new Error(`Use --file ${positional} -f <NAME> instead of a positional path`); } Prevention
- Remember positional <TARGET> is a function/script name, not a path
- Use --file for any .baml source path
- Keep function names free of path-like characters (/, .ext)
When it happens
Trigger: Running e.g. `baml run baml_src/main.baml` — passing a `.baml` file path as the positional target so `looks_like_path(target)` is true.
Common situations: Developers accustomed to other CLIs where a file path is the primary argument type a path-style target.
Understand the failure class
Background: "Unknown argument", "Invalid value", and "must be one of": invalid CLI argument errors explained — this error's family across 35 libraries.
Related errors
- compilation failed: {e:?}
- no `.baml` files found in {}
- could not find packaged playground assets. For local debuggi
- `--file` and `--project` are mutually exclusive; `--file` al
- `{}` is not a file.
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/98c2bb099c54350d.
Report an issue: GitHub.