BoundaryML/baml · error

No optimization runs found in

Error message

No optimization runs found in {}.
Run 'baml-cli optimize' first to create an optimization run.

What it means

Deeper into run_view_mode, the command lists entries inside .baml_optimize and collects valid optimization runs. If the directory exists but contains no parseable runs (runs list empty), it bails with this message naming the directory. Distinct from 907: the base directory exists but is empty or contains no valid run folders.

Solutions

  1. Run `baml-cli optimize` to produce a fresh optimization run.
  2. Inspect .baml_optimize/ contents (`ls -la`) and delete stray/empty entries if they came from older versions.
  3. Ensure the same CLI version is used for optimizing and viewing (upgrade both).
  4. Verify your --from path matches the project whose runs you want to view.

Example fix

// before (empty .baml_optimize/)
baml-cli optimize --view
// after
rm -rf .baml_optimize && baml-cli optimize --from baml_src && baml-cli optimize --view
Defensive patterns

Strategy: validation

Validate before calling

# require at least one run subdirectory
ls -d .baml_optimize/*/ >/dev/null 2>&1 || { echo 'no runs in .baml_optimize'; exit 1; }

Try / catch

catch (e) {
  if (String(e.message).includes('No optimization runs found in')) {
    // rm -rf the stale .baml_optimize and re-run optimize
  }
}

Prevention

When it happens

Trigger: Running `baml-cli optimize --view` when .baml_optimize exists but yields zero run entries — empty directory, only stray files (no run subdirectories), or all subdirectories failing the run-detection predicate.

Common situations: Previously interrupted optimize run that never wrote run data, manually cleaned .baml_optimize leaving the folder behind, runs produced by an older/incompatible CLI version with different folder naming.

Understand the failure class

Background: EmptyResultError / "no results found": when an API or scraper succeeds but returns zero rows — this error's family across 9 libraries.

Related errors


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

Appendix: source

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

            }

            // Find the most recent run_* directory
            let mut runs: Vec<_> = std::fs::read_dir(&optimize_base_dir)?
                .filter_map(|entry| {
                    let entry = entry.ok()?;
                    let path = entry.path();
                    if path.is_dir() {
                        let name = path.file_name()?.to_string_lossy().to_string();
                        if name.starts_with("run_") {
                            return Some(path);
                        }
                    }
                    None
                })
                .collect();

            if runs.is_empty() {
                anyhow::bail!(
                    "No optimization runs found in {}.\n\
                     Run 'baml-cli optimize' first to create an optimization run.",
                    optimize_base_dir.display()
                );
            }

            // Sort by name (which includes timestamp) and take the most recent
            runs.sort();
            runs.pop().unwrap()
        };

        println!("Opening optimization viewer for: {}", run_dir.display());

        // Launch the TUI
        crate::optimize::tui::run_tui(&run_dir)?;

        Ok(OptimizeRunResult::ViewCompleted)
    }

View on GitHub (pinned to bd85ce9dee)