BoundaryML/baml · error
No optimization runs found. Run 'baml-cli optimize' first. E
Error message
No optimization runs found. Run 'baml-cli optimize' first.
Expected directory: {} What it means
In run_view_mode, when no --run-dir is given, the command derives the optimize base directory (.baml_optimize next to the parsed baml_src path or ./.baml_optimize) and expects it to exist. If the base directory is missing, no optimization was ever run (or it ran elsewhere), so the viewer bails with this message including the expected path.
Source
Thrown at engine/baml-runtime/src/cli/optimize.rs:721
/// 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()
);
}
// 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);
}
}
NoneView on GitHub (pinned to bd85ce9dee)
Solutions
- Run `baml-cli optimize` once to create .baml_optimize with run data.
- Verify the expected directory printed in the error; if optimizing a different project, pass matching --from.
- Check you're in the correct project root (relative .baml_optimize resolution).
- Pass --run-dir explicitly if your runs live in a custom location.
Example fix
// before baml-cli optimize --view // no runs yet // after baml-cli optimize --from baml_src # creates runs baml-cli optimize --view --from baml_src
Defensive patterns
Strategy: validation
Validate before calling
# guard before viewing without --run-dir
[ -d .baml_optimize ] || { echo 'run baml-cli optimize first'; exit 1; } Try / catch
catch (e) {
if (String(e.message).includes('No optimization runs found')) {
// trigger a fresh optimize run, then re-run view
}
} Prevention
- Always run optimize before --view.
- Keep .baml_optimize out of clean scripts or restore it via CI cache.
- Run view from the same project root used for optimize.
When it happens
Trigger: Running `baml-cli optimize --view` without --run-dir when the computed .baml_optimize directory does not exist.
Common situations: Running --view before ever running an optimization, running the viewer from a different project/checkout, or .baml_optimize removed by clean tooling.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- Specified run directory does not exist: {}
- failed to clean segmented profiler data at {}
- cannot determine directory of current executable
- `{}` doesn't look like it belongs to a BAML project — no `ba
- VSIX file was not created at expected location
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/ec6d84f26163933c.
Report an issue: GitHub.