BoundaryML/baml · error

` ` doesn't look like it belongs to a BAML project — no…

Error message

`{}` doesn't look like it belongs to a BAML project — no `baml.toml` and no `baml_src/` directory found in it or its ancestors.

What it means

Same root-cause as the source-resolution failure: `resolve_project_name` needs a valid project layout (a `baml.toml` or `baml_src/` in the directory or an ancestor) to derive a project name, and none was found. The CLI bails rather than guessing a name for a non-project directory.

Solutions

  1. Add a `baml.toml` with an explicit project name to the project root
  2. Create the `baml_src/` directory so the layout resolves and the directory name can be used
  3. Run `baml init` to scaffold a proper project
  4. Pass `--project <DIR>` targeting a real BAML project

Example fix

// before (empty dir)
$ baml open
// after
$ baml init   # creates baml_src/ so the project name resolves
Defensive patterns

Strategy: validation

Validate before calling

const fs = require('fs'), path = require('path');
function hasBamlLayout(dir) {
  let cur = path.resolve(dir);
  while (true) {
    if (fs.existsSync(path.join(cur, 'baml.toml')) || fs.existsSync(path.join(cur, 'baml_src'))) return true;
    const parent = path.dirname(cur);
    if (parent === cur) return false;
    cur = parent;
  }
}
if (!hasBamlLayout(process.cwd())) throw new Error('no baml.toml or baml_src/ found; project name cannot be resolved');

Try / catch

try { const name = baml.resolveProjectName(dir); } catch (e) { if (String(e).includes("doesn't look like it belongs to a BAML project")) { console.error('Initialize the project first: baml init'); } throw e; }

Prevention

When it happens

Trigger: Calling `resolve_project_name(from)` when `resolve_project_layout` returns None — no `baml.toml` and no `baml_src/` at or above the search start path.

Common situations: Same as project-source resolution failures: invoking the CLI outside a BAML project, bad `--project` path, or a project whose manifest/src dir was removed.

Understand the failure class

Background: "X is required", "must be set", "cannot be empty": the missing-required-config error family, from Vertex AI project/location to WeChat keys — this error's family across 18 libraries.

Related errors


AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12). Data as JSON: /api/errors/ff803b76860bfa9c. Report an issue: GitHub.

Appendix: source

Thrown at baml_language/crates/baml_cli/src/project_load.rs:487

pub(crate) fn validate_baml_toml(toml_path: &Path) -> Result<String> {
    let content = std::fs::read_to_string(toml_path)
        .with_context(|| format!("failed to read {}", toml_path.display()))?;
    let manifest = baml_db::manifest::parse(&content)
        .with_context(|| format!("failed to parse {}", toml_path.display()))?;
    baml_db::manifest::reject_stdlib_only_tables(&manifest, toml_path)?;
    Ok(baml_db::manifest::package_name(&manifest, toml_path)?)
}

/// Resolve the project's name for output-artifact naming (used by `baml
/// pack`). Prefers `[package].name` from `<root>/baml.toml` when a manifest
/// is present (guaranteed valid for any path we've loaded as a project).
/// For a manifest-less `baml_src/` project, falls back to the project
/// directory's name — the way `cargo` names a target after its directory
/// when no explicit name is given.
pub(crate) fn resolve_project_name(from: Option<&Path>) -> Result<String> {
    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()

View on GitHub (pinned to bd85ce9dee)