BoundaryML/baml · error

does not exist (expected a directory containing BAML files)

Error message

{dir:#?} does not exist (expected a directory containing BAML files)

What it means

baml_src_files() validates the directory it's asked to scan for .baml files before walking it. The very first check confirms the path exists at all; if it doesn't, the function bails with this error embedding the debug-formatted path. This is typically the first failure users see when the baml_src path is misconfigured.

Solutions

  1. Run the command from the project root so the relative baml_src path resolves (or pass an absolute path)
  2. Verify the directory exists with `ls baml_src` and create/rename it if it was moved or deleted
  3. Fix the configured baml_src path in your tooling (baml-cli args, editor extension settings, or runtime LoadSrcArgs)
  4. If bundling an app, ensure the baml_src directory is included in the artifact next to the binary

Example fix

// before
let files = baml_src_files(&PathBuf::from("./baml_sorc"))?; // typo

// after
let files = baml_src_files(&PathBuf::from("./baml_src"))?;
Defensive patterns

Strategy: validation

Validate before calling

import fs from 'fs';
const dir = './baml_src';
if (!fs.existsSync(dir)) throw new Error(`${dir} does not exist; run from the project root or fix the baml_src path`);

Try / catch

try {
  const files = bamlSrcFiles(dir);
} catch (e) {
  if (/does not exist/i.test(e.message)) {
    console.error(`Directory not found: ${e.message}. Check cwd and the baml_src path configuration.`);
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling baml_src_files (via project loading / baml-cli commands / LoadSrcArgs with baml_src path) with a PathBuf that does not exist on disk.

Common situations: Running the CLI from the wrong working directory so the relative baml_src/ path doesn't resolve; deleting or renaming the baml_src folder; misconfigured project root in an editor plugin or a packaged app where the sources weren't bundled.

Related errors


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

Appendix: source

Thrown at engine/baml-runtime/src/lib.rs:2244

    }

    fn get_test_type_builder(
        &self,
        function_name: &str,
        test_name: &str,
    ) -> Result<Option<TypeBuilder>> {
        self.get_test_type_builder_impl(function_name, test_name)
    }
}

#[cfg(not(target_arch = "wasm32"))]
pub fn baml_src_files(dir: &std::path::PathBuf) -> Result<Vec<PathBuf>> {
    static VALID_EXTENSIONS: [&str; 1] = ["baml"];

    log::trace!("Reading files from {:#}", dir.to_string_lossy());

    if !dir.exists() {
        anyhow::bail!("{dir:#?} does not exist (expected a directory containing BAML files)",);
    }
    if dir.is_file() {
        return Err(anyhow::anyhow!(
            "{dir:#?} is a file, not a directory (expected a directory containing BAML files)",
        ));
    }
    if !dir.is_dir() {
        return Err(anyhow::anyhow!(
            "{dir:#?} is not a directory (expected a directory containing BAML files)",
        ));
    }

    let src_files = walkdir::WalkDir::new(dir)
        .into_iter()
        .filter_map(|e| match e {
            Ok(e) => Some(e),
            Err(e) => {
                log::error!("Error while reading files from {dir:#?}: {e}");

View on GitHub (pinned to bd85ce9dee)