BoundaryML/baml · error

No tests were found that can be run. Please add tests and…

Error message

No tests were found that can be run. Please add tests and try again.

What it means

`baml-cli optimize` optimizes BAML functions by evaluating their test cases. Before the first optimization cycle it checks orchestrator.num_tests(); if zero tests exist there is nothing to evaluate, so it bails with this message. The first cycle needs at least 2 * num_tests evaluations, hence the guard.

Solutions

  1. Add at least one `test { ... }` block to the BAML function you want to optimize.
  2. Check your --from / baml_src path points at the directory containing the tests.
  3. Remove any test-name filters/selectors that exclude all tests.
  4. Run `baml-cli test` first to confirm tests are discoverable and passing.

Example fix

// before (no tests)
function ExtractResume(text: string) -> Resume { ... }
// after
test ExtractResumeTest {
  functions: [ExtractResume]
  args: { text: "John Doe, Software Engineer" }
}
Defensive patterns

Strategy: validation

Validate before calling

# ensure tests exist before optimizing
grep -r '^test ' baml_src/ >/dev/null || { echo 'add test blocks first'; exit 1; }

Try / catch

catch (e) {
  if (String(e.message).includes('No tests were found')) {
    // surface guidance: add test blocks to your BAML functions
  }
}

Prevention

When it happens

Trigger: Running `baml-cli optimize` when the optimization run resolves to zero runnable tests — empty or missing test blocks in the targeted baml files, or a --from/selection that filters out all tests.

Common situations: Optimizing a project whose .baml files have functions but no `test` blocks, wrong baml_src path, tests filtered by name/pattern that matched nothing, using optimize before writing any tests.

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/e697192b910f01a8. Report an issue: GitHub.

Appendix: source

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

                function_filter: self.function.clone(),
                test_filter,
                trials,
                max_evals: self.max_evals,
                parallel: self.parallel,
                objectives,
                verbose: self.verbose,
                quiet: !self.no_ui, // Suppress output when TUI is active
                env_vars,
                baml_src_path: from.clone(),
                feature_flags,
            },
        )?;

        // Getting through the first optimization cycle requires at least `2 * num_tests` evaluations:
        // one pass for the initial candidate and another for the first improved candidate.
        let num_tests = orchestrator.num_tests();
        if num_tests == 0 {
            anyhow::bail!(
                "\n{} No tests were found that can be run. Please add tests and try again.",
                "error:".red().bold()
            );
        }

        let min_evals_for_one_cycle = 2 * num_tests;
        if self.max_evals < min_evals_for_one_cycle {
            eprintln!(
                "\n{} --max-evals ({}) is insufficient to run even a single optimization cycle.",
                "error:".red().bold(),
                self.max_evals.to_string().bold()
            );
            eprintln!(
                "  Increase {} to at least {} and try again {}",
                "--max-evals".bold(),
                min_evals_for_one_cycle.to_string().bold(),
                format!(
                    "(Initial evaluation ({num_tests}) + first trial ({num_tests}) = {})",

View on GitHub (pinned to bd85ce9dee)