BoundaryML/baml · error
is a file, not a directory (expected a directory containing…
Error message
{dir:#?} is a file, not a directory (expected a directory containing BAML files) What it means
baml_src_files() expects the given path to be a directory containing .baml files. After confirming the path exists, it checks that the path is not a regular file; pointing it at a file raises this error. It guards against passing something like a single .baml file or a config file where a directory is expected.
Solutions
- Pass the directory (e.g. ./baml_src), not a file inside it
- Remove any trailing filename from the configured baml_src path in your CLI args or runtime config
- Point editor extension settings at the baml_src folder, not an individual .baml file
Example fix
// before
baml_src_files(&PathBuf::from("baml_src/main.baml"))?
// after
baml_src_files(&PathBuf::from("baml_src"))? Defensive patterns
Strategy: validation
Validate before calling
import fs from 'fs';
const p = './baml_src';
if (fs.existsSync(p) && !fs.statSync(p).isDirectory()) throw new Error(`${p} must be the baml_src directory, not a file`); Type guard
function isDirectory(p: string): boolean {
try { return fs.statSync(p).isDirectory(); } catch { return false; }
} Try / catch
try {
bamlSrcFiles(dir);
} catch (e) {
if (/is a file, not a directory/i.test(e.message)) {
console.error(`Pass the folder (e.g. ./baml_src) instead of a file: ${dir}`);
}
throw e;
} Prevention
- Point configs and editor settings at the baml_src folder, never an individual .baml file
- Strip trailing filenames from path variables before calling generation APIs
- Keep a single source of truth for the baml_src path in your build scripts
When it happens
Trigger: Calling baml_src_files with a PathBuf such as "baml_src/main.baml" or any other file path instead of the directory (e.g. "./baml_src").
Common situations: Configuring the editor extension or runtime with the path to a single .baml file instead of the source folder; accidentally passing a config file (baml.json) as the source path; shell scripts that append a filename to the source directory.
Related errors
- does not exist (expected a directory containing BAML files)
- is not a directory (expected a directory containing BAML…
- Expected --from ' ' to be a baml_src/ directory, but it…
- Expected --from ' ' to be a baml_src/ directory, but it is…
- Failed to gather files from directory
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/917df0c56083ae5c.
Report an issue: GitHub.
Appendix: source
Thrown at engine/baml-runtime/src/lib.rs:2247
&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}");
None
}
})View on GitHub (pinned to bd85ce9dee)