{"record":{"id":"eb7321a218424608","repo":"BoundaryML/baml","slug":"no-baml-project-found-run-baml-init-before-adding-a","errorCode":null,"errorMessage":"no BAML project found; run `baml init` before adding a generator","messagePattern":"no BAML project found; run `baml init` before adding a generator","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"baml_language/crates/baml_cli/src/generate.rs","lineNumber":104,"sourceCode":"/// `baml.toml`.\nstruct GeneratorDef {\n    name: String,\n    output_type: OutputType,\n    /// Resolved output directory (absolute).\n    output_dir: PathBuf,\n    /// Required `naming_convention` from the generator section. No default\n    /// is permitted — generators must spell out the policy explicitly.\n    naming_convention: NamingConvention,\n    /// Required for Go so generated packages can import the SDK root and one\n    /// another. Other generators leave this unset.\n    sdk_import_path: Option<String>,\n    max_typed_union_arity: usize,\n}\n\nimpl AddGeneratorArgs {\n    fn run(&self) -> Result<crate::ExitCode> {\n        let root = crate::project_load::find_project_root_from(self.from.as_deref())?.ok_or_else(\n            || anyhow!(\"no BAML project found; run `baml init` before adding a generator\"),\n        )?;\n        let toml_path = root.join(\"baml.toml\");\n        if !toml_path.is_file() {\n            anyhow::bail!(\n                \"`{}` has no baml.toml; run `baml init` before adding a generator\",\n                root.display()\n            );\n        }\n\n        let content = std::fs::read_to_string(&toml_path)\n            .with_context(|| format!(\"failed to read {}\", toml_path.display()))?;\n        let manifest = baml_db::manifest::parse(&content)\n            .with_context(|| format!(\"failed to parse {}\", toml_path.display()))?;\n        baml_db::manifest::package_name(&manifest, &toml_path)?;\n        // Every other manifest reader rejects these, so accepting them here\n        // would write a generator into a file that the next build refuses to\n        // load, reporting a failure that names neither this command nor the\n        // table it choked on.","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/baml_cli/src/generate.rs#L86-L122","documentation":"`baml generate add-generator` (the `--from` based generator-adding flow) first resolves the BAML project root via `find_project_root_from`. When no project root can be found in or above the given directory, it throws this error telling the user to initialize a project with `baml init` first.","triggerScenarios":"Running the add-generator command with `--from` pointing at (or defaulting to) a directory that is not inside a BAML project — no baml.toml/baml_src markers found walking upward.","commonSituations":"Running the command outside a project (e.g. in $HOME or a fresh directory), pointing `--from` at the wrong subdirectory, or a project whose baml.toml was deleted/renamed so the root can no longer be detected.","solutions":["Run `baml init` in the directory to create a BAML project first.","cd into your actual BAML project (the one containing baml.toml) before running the command.","Pass the correct path via --from, e.g. --from path/to/my-baml-project.","Verify the project marker file baml.toml still exists at the project root and restore it if deleted."],"exampleFix":"// before (in a non-project directory)\nbaml generate add-generator --from ./scratch\n// after\nbaml init ./my-project\ncd my-project && baml generate add-generator","handlingStrategy":"validation","validationCode":"#!/usr/bin/env bash\nif [ ! -f baml.toml ] && ! find . -maxdepth 3 -name baml.toml -print -quit | grep -q .; then\n  echo \"no BAML project here; run: baml init\" >&2; exit 1\nfi\nbaml generate add-generator \"$@\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always run generator commands from inside a project containing baml.toml.","Run `baml init` as the first step of any new-project script.","Pass an explicit --from pointing at the project root in CI scripts."],"tags":["cli","project-setup","not-found"],"backgroundTag":"config-file-not-found","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}