BoundaryML/baml · error

`{}` doesn't look like it belongs to a BAML project — no `ba

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

`workspace_roots` in the playground command resolves the BAML project root by walking up from a starting path looking for a `baml.toml` manifest or a `baml_src/` directory. If `find_baml_project_root` finds neither in the start directory nor any ancestor, it bails with this message. It's the playground's way of refusing to run outside any recognizable BAML project.

Source

Thrown at baml_language/crates/baml_cli/src/playground_command.rs:115

    false
}

fn workspace_roots(from: Option<&Path>, file: Option<&Path>) -> Result<Vec<PathBuf>> {
    // The playground's LSP currently discovers projects from marker-bearing
    // workspace roots. Unlike the compile/run commands, it cannot yet carry a
    // settings root and a disjoint source root as one project, so retain its
    // marker requirement instead of accepting a root it would silently ignore.
    if file.is_some() {
        return match resolve_source_location(from, file, None)? {
            SourceLocation::StandaloneFile { file, .. } => Ok(vec![file]),
            SourceLocation::Project { .. } => unreachable!("file mode resolved as a project"),
        };
    }

    let search_start = resolve_project_search_start(from)
        .with_context(|| "could not resolve playground project search path")?;
    let Some(marked_root) = find_baml_project_root(&search_start) 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 project = load_project_from(Some(&marked_root))?;
    let root = project.root().to_path_buf();
    if project.files.is_empty() {
        anyhow::bail!("no `.baml` files found in {}", root.display());
    }
    Ok(vec![root])
}

fn resolve_playground_assets() -> Result<Option<PathBuf>> {
    if std::env::var_os("BAML_PLAYGROUND_DEV_PORT").is_some()
        || std::env::var_os("BAML_PLAYGROUND_DIR").is_some()
    {
        return Ok(None);

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. cd into the BAML project directory (or a subdirectory of it) before launching the playground.
  2. Add a `baml.toml` manifest at the project root, or rename/ensure the source directory is `baml_src/`, so the marker walk-up finds it.
  3. If using a standalone file, place it inside a directory with a `baml.toml` or `baml_src/` marker (or an ancestor of it).
  4. Verify with `ls baml.toml baml_src` from your current directory and each ancestor to confirm a marker exists on the path.

Example fix

// before: running playground from an unrelated dir with sources elsewhere
$ cd ~ && baml-cli playground
// after: create the marker at the project root, then run from the project
$ cd ~/my-project && mkdir -p baml_src && baml-cli playground
Defensive patterns

Strategy: validation

Validate before calling

import fs from 'node:fs';
import path from 'node:path';

function findBamlRoot(start: string): string | null {
  let dir = path.resolve(start);
  while (true) {
    if (fs.existsSync(path.join(dir, 'baml.toml')) || fs.existsSync(path.join(dir, 'baml_src'))) return dir;
    const parent = path.dirname(dir);
    if (parent === dir) return null;
    dir = parent;
  }
}
// call findBamlRoot(process.cwd()) before launching the playground

Type guard

function isBamlProjectRoot(dir: string): boolean {
  return fs.existsSync(path.join(dir, 'baml.toml')) || fs.existsSync(path.join(dir, 'baml_src'));
}

Try / catch

try {
  const roots = await workspace_roots(from);
  startPlayground(roots);
} catch (e) {
  if (String(e).includes('baml.toml')) {
    console.error('No BAML project found: add baml.toml or baml_src/ at your project root, then rerun.');
    process.exitCode = 1;
  } else throw e;
}

Prevention

When it happens

Trigger: Running the playground (`run`) or tests like `project_mode_errors_without_project_marker` from/pointing at a directory that contains no `baml.toml` and no `baml_src/` anywhere in itself or its ancestors — e.g. passing a standalone file path outside a project or launching from $HOME/tmp.

Common situations: Launching the playground from the wrong working directory (repo root instead of the BAML package, or an unrelated folder); the project lacks `baml.toml` and its source dir isn't named `baml_src/`; pointing `--file` at a standalone `.baml` file kept outside any project tree.

Related errors


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