BoundaryML/baml · error
function `{function_name}` not found
Error message
function `{function_name}` not found What it means
Runtime lookup failure in `baml run`: the target named on the command line (or via a script's --function) does not match any function declared in the loaded BAML project. The engine's find_user_function returned nothing before execution could start — the name may be misspelled, missing the user. prefix convention, or defined in a file outside the project root.
Source
Thrown at baml_language/crates/baml_cli/src/run_command.rs:570
target,
&project_root,
));
};
// Patch `argv[1]` to the engine-canonical display name (strips
// `user.` prefix) so scripts and the direct path agree.
if let Some(info) = engine.find_user_function(&function_name) {
let display = info.display_name.clone();
let mut patched: Vec<String> = engine.argv().to_vec();
if patched.len() >= 2 && (was_script || display != *target) {
patched[1] = display;
engine.set_argv(patched);
}
}
let func_info = engine
.find_user_function(&function_name)
.ok_or_else(|| anyhow!("function `{function_name}` not found"))?;
baml_exec::validate_help_param(&engine, &function_name)?;
let target_is_typed = !func_info.param_names.is_empty();
let parsed = if target_is_typed {
let display = function_name
.strip_prefix("user.")
.unwrap_or(&function_name);
let bin_name = format!("baml run {display} --");
match baml_exec::parse_target_argv(
&bin_name,
&function_name,
&func_info,
&effective_target_args,
) {
Ok(p) => p,
Err(err) => return surface_clap_error(reporter, err),
}
} else {View on GitHub (pinned to bd85ce9dee)
Solutions
- Check the function name spelling and that it exists in the loaded `.baml` sources
- List available functions and pick the correct one
- Ensure the file defining the function is inside the project root so it is compiled
Example fix
// before baml run --file baml_src/main.baml -f MyFuntion // after baml run --file baml_src/main.baml -f MyFunction
Defensive patterns
Strategy: validation
Validate before calling
const fns = engine.user_functions().map(f => f.qualified_name.replace(/^user\./, '')); if (!fns.includes(name)) throw new Error(`function '${name}' not found; available: ${fns.join(', ')}`); Prevention
- Verify function names against the .baml sources before running
- Keep baml.toml scripts in sync with renamed/deleted functions
- Run from a project root that includes the file defining the function
When it happens
Trigger: `run_single_target` calls `engine.find_user_function(&function_name)` and receives None — the name came from `--function`/`-f` or a script expansion.
Common situations: Typo in the function name; the function exists in a different `.baml` file not included in the project; prefixing mistakes (functions are qualified like `user.<name>`); a script in `baml.toml` referencing a deleted function.
Understand the failure class
Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.
Related errors
- function `{target_name}` not found
- LLM function not found: {}: {}
- no BAML project found; run `baml init` before adding a gener
- `{}` has no baml.toml; run `baml init` before adding a gener
- compilation failed: {e:?}
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/828da57858b66bfb.
Report an issue: GitHub.