BoundaryML/baml · error
could not derive a project name from
Error message
could not derive a project name from `{}`; pass `-o <PATH>` to name the output. What it means
A valid project layout was found but its root path has no representable file name (e.g. `/`, `..`, or a non-UTF-8 path), so the CLI cannot derive a default project name from the directory name. It asks the user to name the output explicitly instead.
Solutions
- Pass `-o <PATH>` to name the output explicitly
- Run from inside a normally-named project directory
- Pass `--project <DIR>` with a concrete named directory instead of `/` or `..` paths
Example fix
// before baml generate --project / // after baml generate -o ./out --project /
Defensive patterns
Strategy: validation
Validate before calling
const path = require('path');
const root = path.resolve(projectDir);
const name = path.basename(root);
if (!name || name === path.sep || /[\u0080-\uFFFF]/.test(name) || root === path.parse(root).root) {
throw new Error('project root has no usable name; pass -o <PATH>');
} Try / catch
try { baml.generate({ project: '/' }); } catch (e) { if (String(e).includes('could not derive a project name')) { return baml.generate({ project: '/', output: './out' }); } throw e; } Prevention
- Never use `/` or `..`-terminated paths as the project root
- Always pass `-o <PATH>` in scripts where the project dir may be unusual
- Use named, ASCII project directories
When it happens
Trigger: `resolve_project_name` succeeds in resolving a layout, but `layout.root.file_name()` returns None or a non-UTF-8 name — typically when the project root is `/` or a path ending in `..`.
Common situations: Running the CLI with the filesystem root as the project directory; passing `--project /`; using `..`-terminated paths; exotic non-UTF-8 directory names.
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
- are mutually exclusive dispatch modes — pick one.
- {bail_context}
- Cannot generate HIR/bytecode due to validation errors
- compilation failed
- compilation failed
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/5b6840e146b097a8.
Report an issue: GitHub.
Appendix: source
Thrown at baml_language/crates/baml_cli/src/project_load.rs:503
let search_start = resolve_search_start(from)?;
let Some(layout) = resolve_project_layout(from)? else {
anyhow::bail!(
"`{}` doesn't look like it belongs to a BAML project — no `baml.toml` \
and no `baml_src/` directory found in it or its ancestors.",
search_start.display()
);
};
let toml_path = layout.root.join(BAML_TOML);
if toml_path.exists() {
return validate_baml_toml(&toml_path);
}
layout
.root
.file_name()
.and_then(|name| name.to_str())
.map(str::to_string)
.ok_or_else(|| {
anyhow::anyhow!(
"could not derive a project name from `{}`; pass `-o <PATH>` to name the output.",
layout.root.display()
)
})
}
#[cfg(test)]
mod tests {
use std::fs;
use tempfile::TempDir;
use super::*;
/// An explicit source directory is intentionally sufficient even without
/// `baml.toml` or a `baml_src/` wrapper.
#[test]
fn accepts_explicit_unmarked_source_directory() {View on GitHub (pinned to bd85ce9dee)