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.
add a `baml_src/` directory with your `.baml` files, run `baml init`, or pass `--project <DIR>` to load an explicit source directory.

What it means

BAML CLI could not locate a BAML project root from the given directory: neither a `baml.toml` manifest nor a `baml_src/` directory exists in the directory or any ancestor. `resolve_project_sources` refuses to load sources because there is nothing to compile. This guards against silently compiling an empty or wrong project.

Solutions

  1. Run `baml init` in the directory to create a `baml_src/` with sample `.baml` files
  2. Create a `baml_src/` directory containing your `.baml` files in the project root
  3. Pass `--project <DIR>` pointing at a directory that contains `baml.toml` or `baml_src/`
  4. cd into the actual BAML project directory before running the command

Example fix

// before
baml generate --project ./wrong-dir
// after
baml generate --project ./my-baml-project  # contains baml.toml and baml_src/
Defensive patterns

Strategy: validation

Validate before calling

import fs from 'fs';
function isBamlProject(dir) {
  let cur = require('path').resolve(dir);
  while (true) {
    if (fs.existsSync(require('path').join(cur, 'baml.toml')) ||
        fs.existsSync(require('path').join(cur, 'baml_src'))) return true;
    const parent = require('path').dirname(cur);
    if (parent === cur) return false;
    cur = parent;
  }
}
if (!isBamlProject('./')) throw new Error('not a BAML project: run baml init or pass --project');

Try / catch

try { await baml.loadProject(dir); } catch (e) { if (String(e).includes('baml_src')) { console.error('Run `baml init` or pass --project <DIR>'); process.exit(1); } throw e; }

Prevention

When it happens

Trigger: Calling `resolve_project_sources(from)` (via `load_project_from_inner`, `open`, or `--project <DIR>`) when the resolved search start directory contains no `baml.toml` and no `baml_src/` directory anywhere up its ancestor chain.

Common situations: Running `baml` commands outside a project; typo'd `--project` path; project initialized without `baml init`; renamed/deleted `baml_src/` directory; running from a subdirectory of an unrelated folder.

Understand the failure class

Background: "Config file not found": what it means and how to fix it in docker-sync, Maven, Vagrant, Turborepo and other tools — this error's family across 60 libraries.

Related errors


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

Appendix: source

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

/// hit the database (and everything downstream of it: typecheck, emit) is
/// skipped entirely; on a miss [`build_db_from_sources`] reuses these
/// already-read contents instead of re-reading from disk.
pub(crate) struct ResolvedProject {
    /// Canonical settings root: the directory holding the effective
    /// `baml.toml`, or the explicit standalone source root without a manifest.
    pub root: PathBuf,
    /// `baml.toml` content when present (already validated).
    pub manifest: Option<String>,
    /// Discovered `.baml` files with contents, in discovery (sorted) order.
    pub files: Vec<(PathBuf, String)>,
}

/// Resolve the project root, validate the manifest, and read every source
/// file into memory. The strict-path front half of [`load_project_from`].
pub(crate) fn resolve_project_sources(from: Option<&Path>) -> Result<ResolvedProject> {
    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.\n\
             add a `baml_src/` directory with your `.baml` files, run `baml init`, \
             or pass `--project <DIR>` to load an explicit source directory.",
            search_start.display()
        );
    };

    let toml_path = layout.root.join(BAML_TOML);

    // Manifest validation, Cargo-style: when a `baml.toml` is present it must
    // be valid (`[package].name` mandatory). Failing here — before any source
    // discovery or compilation — gives the same fast feedback as a malformed
    // `Cargo.toml`, rather than crashing several seconds in when a packaging
    // verb tries to use the name. A manifest-less `baml_src/` project skips
    // this: `baml.toml` is opt-in.
    let manifest = if toml_path.exists() {
        let content = std::fs::read_to_string(&toml_path)

View on GitHub (pinned to bd85ce9dee)