BoundaryML/baml · error

Specified run directory does not exist: {}

Error message

Specified run directory does not exist: {}

What it means

In run_view_mode (`baml-cli optimize --view`), if the user passes an explicit run directory via --run-dir, the command validates it exists before opening the TUI viewer. A non-existent path causes this bail. It means the previous optimization run directory you pointed at was deleted, moved, or misspelled.

Source

Thrown at engine/baml-runtime/src/cli/optimize.rs:709

        println!("\n{}", "=".repeat(60));
        println!("Applying changes...");
        crate::optimize::applier::write_changes_to_disk(&changes)?;

        for change in &changes {
            println!("  Updated: {}", change.relative_path);
        }
        println!("\nChanges applied successfully!");
        println!("Use 'git diff' to review changes, or 'git checkout .' to revert.");

        Ok(())
    }

    /// Run the TUI viewer mode
    fn run_view_mode(&self) -> Result<OptimizeRunResult> {
        let run_dir = if let Some(ref dir) = self.run_dir {
            // Use explicitly specified run directory
            if !dir.exists() {
                anyhow::bail!("Specified run directory does not exist: {}", dir.display());
            }
            dir.clone()
        } else {
            // Find the most recent run in .baml_optimize/
            let from = BamlRuntime::parse_baml_src_path(&self.from)?;
            let optimize_base_dir = from
                .parent()
                .map(|p| p.join(".baml_optimize"))
                .unwrap_or_else(|| PathBuf::from(".baml_optimize"));

            if !optimize_base_dir.exists() {
                anyhow::bail!(
                    "No optimization runs found. Run 'baml-cli optimize' first.\n\
                     Expected directory: {}",
                    optimize_base_dir.display()
                );
            }

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Check the path with `ls <dir>` and correct typos.
  2. Use an absolute path if running from a different working directory.
  3. Omit --run-dir so the viewer auto-selects the most recent run in .baml_optimize/.
  4. Re-run `baml-cli optimize` to regenerate a run directory if it was deleted.

Example fix

// before
baml-cli optimize --view --run-dir .baml_optimize/run_2026-09-10  // deleted
// after
baml-cli optimize --view   # auto-picks latest run in .baml_optimize/
Defensive patterns

Strategy: validation

Validate before calling

# guard before viewing
[ -d "$RUN_DIR" ] || { echo "run dir missing: $RUN_DIR"; exit 1; }

Try / catch

catch (e) {
  if (String(e.message).includes('Specified run directory does not exist')) {
    // drop --run-dir to auto-select the latest run
  }
}

Prevention

When it happens

Trigger: Running `baml-cli optimize --view --run-dir <dir>` where <dir>.exists() is false.

Common situations: Typo in the path, viewing from a different working directory with a relative path, .baml_optimize run folder cleaned up by CI or .gitignore/clean scripts.

Related errors


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