BoundaryML/baml · error

Expected --from '{}' to be a baml_src/ directory, but it is

Error message

Expected --from '{}' to be a baml_src/ directory, but it is not

What it means

Path validation in the runtime's project loader: the --from argument exists but is a regular file (or symlink to one), not a directory. The runtime requires the baml_src/ project directory because it globs *.baml files beneath it; passing a single .baml file path to --from trips this guard after the existence check passes.

Source

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

            async_runtime: rt.clone(),
            publisher_env_vars: Some(publisher_env_vars),
        };

        Ok(runtime)
    }

    pub fn parse_baml_src_path(path: impl Into<PathBuf>) -> Result<PathBuf> {
        let mut path: PathBuf = path.into();

        if !path.exists() {
            anyhow::bail!(
                "Expected --from '{}' to be a baml_src/ directory, but it does not exist",
                path.display()
            );
        }

        if !path.is_dir() {
            anyhow::bail!(
                "Expected --from '{}' to be a baml_src/ directory, but it is not",
                path.display()
            );
        }

        if path.file_name() != Some(std::ffi::OsStr::new("baml_src")) {
            let contained = path.join("baml_src");

            if contained.exists() && contained.is_dir() {
                path = contained;
            } else {
                anyhow::bail!(
                    "Expected --from '{}' to be a baml_src/ directory, but it is not",
                    path.display()
                );
            }
        }

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Point --from at the baml_src directory itself, not a file inside it
  2. Use the directory path (e.g. ./baml_src) in scripts and commands
  3. If the path is generated, assert path.is_dir() before invoking the runtime

Example fix

// before
BamlRuntime::from_directory("./baml_src/greet.baml")?;
// after
BamlRuntime::from_directory("./baml_src")?;
Defensive patterns

Strategy: validation

Validate before calling

use std::path::Path;
fn validate_from(p: &str) -> Result<(), String> {
    let path = Path::new(p);
    if path.exists() && !path.is_dir() {
        return Err(format!("--from '{}' must be a directory", p));
    }
    Ok(())
}

Prevention

When it happens

Trigger: Passing a file path (e.g. ./baml_src/main.baml or a config file) where a directory is expected via --from or parse_baml_src_path.

Common situations: Tab-completion grabbing a file instead of the folder; passing a single .baml file expecting it to work; scripts interpolating the wrong variable.

Related errors


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