{"record":{"id":"e697192b910f01a8","repo":"BoundaryML/baml","slug":"no-tests-were-found-that-can-be-run-please-add-tests-and-try","errorCode":null,"errorMessage":"No tests were found that can be run. Please add tests and try again.","messagePattern":"No tests were found that can be run\\. Please add tests and try again\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-runtime/src/cli/optimize.rs","lineNumber":389,"sourceCode":"                function_filter: self.function.clone(),\n                test_filter,\n                trials,\n                max_evals: self.max_evals,\n                parallel: self.parallel,\n                objectives,\n                verbose: self.verbose,\n                quiet: !self.no_ui, // Suppress output when TUI is active\n                env_vars,\n                baml_src_path: from.clone(),\n                feature_flags,\n            },\n        )?;\n\n        // Getting through the first optimization cycle requires at least `2 * num_tests` evaluations:\n        // one pass for the initial candidate and another for the first improved candidate.\n        let num_tests = orchestrator.num_tests();\n        if num_tests == 0 {\n            anyhow::bail!(\n                \"\\n{} No tests were found that can be run. Please add tests and try again.\",\n                \"error:\".red().bold()\n            );\n        }\n\n        let min_evals_for_one_cycle = 2 * num_tests;\n        if self.max_evals < min_evals_for_one_cycle {\n            eprintln!(\n                \"\\n{} --max-evals ({}) is insufficient to run even a single optimization cycle.\",\n                \"error:\".red().bold(),\n                self.max_evals.to_string().bold()\n            );\n            eprintln!(\n                \"  Increase {} to at least {} and try again {}\",\n                \"--max-evals\".bold(),\n                min_evals_for_one_cycle.to_string().bold(),\n                format!(\n                    \"(Initial evaluation ({num_tests}) + first trial ({num_tests}) = {})\",","sourceCodeStart":371,"sourceCodeEnd":407,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-runtime/src/cli/optimize.rs#L371-L407","documentation":"`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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Add at least one `test { ... }` block to the BAML function you want to optimize.","Check your --from / baml_src path points at the directory containing the tests.","Remove any test-name filters/selectors that exclude all tests.","Run `baml-cli test` first to confirm tests are discoverable and passing."],"exampleFix":"// before (no tests)\nfunction ExtractResume(text: string) -> Resume { ... }\n// after\ntest ExtractResumeTest {\n  functions: [ExtractResume]\n  args: { text: \"John Doe, Software Engineer\" }\n}\n","handlingStrategy":"validation","validationCode":"# ensure tests exist before optimizing\ngrep -r '^test ' baml_src/ >/dev/null || { echo 'add test blocks first'; exit 1; }","typeGuard":null,"tryCatchPattern":"catch (e) {\n  if (String(e.message).includes('No tests were found')) {\n    // surface guidance: add test blocks to your BAML functions\n  }\n}","preventionTips":["Write test blocks for every function you plan to optimize.","Run `baml-cli test` first to confirm tests resolve.","Double-check --from and any test filters before optimize."],"tags":["baml","cli","optimize","tests"],"backgroundTag":"empty-result-set","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}