{"record":{"id":"51e78e816cf64d5c","repo":"BoundaryML/baml","slug":"is-not-a-baml-source-file-use-a-baml-file-with-file","errorCode":null,"errorMessage":"`{}` is not a BAML source file. Use a `.baml` file with `--file`.","messagePattern":"`(.+?)` is not a BAML source file\\. Use a `\\.baml` file with `--file`\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"baml_language/crates/baml_cli/src/project_load.rs","lineNumber":73,"sourceCode":"        Some(reporter) => load_project_from_reporting(from, reporter)?,\n        None => load_project_from(from)?,\n    };\n    let root = loaded.root().to_path_buf();\n    Ok(SourceLocation::Project {\n        root,\n        files: loaded.files,\n    })\n}\n\npub(crate) fn resolve_standalone_file(file_path: &Path) -> Result<PathBuf> {\n    let display = file_path.display().to_string();\n    let canonical =\n        std::fs::canonicalize(file_path).with_context(|| format!(\"file not found: {display}\"))?;\n    if !canonical.is_file() {\n        anyhow::bail!(\"`{}` is not a file.\", canonical.display());\n    }\n    if canonical.extension().and_then(|ext| ext.to_str()) != Some(\"baml\") {\n        anyhow::bail!(\n            \"`{}` is not a BAML source file. Use a `.baml` file with `--file`.\",\n            canonical.display()\n        );\n    }\n    Ok(canonical)\n}\n\n/// Resolve `from` (or cwd when omitted) and load all discovered `.baml` files\n/// into a fresh\n/// [`ProjectDatabase`]. Returns the database, the canonical project root,\n/// and the list of loaded files. Used by the build/execute commands\n/// (`run`/`test`/`generate`/`pack`).\n///\n/// **`baml.toml` is opt-in.** A directory is a BAML project if it has\n/// *either* a `baml.toml` *or* a `baml_src/` directory — `baml.toml` is\n/// only needed when you actually use one of its features (dependencies,\n/// version locks, `[scripts]`, multiple packages). The two cases:\n///","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/baml_cli/src/project_load.rs#L55-L91","documentation":"After confirming the --file path is a regular file, resolve_standalone_file checks its extension is `.baml`. A non-`.baml` file is rejected because --file only accepts BAML source files. This prevents compiling config files, generated code, or unrelated sources as BAML.","triggerScenarios":"Passing a file whose canonical path extension is not `baml` (e.g. .txt, .json, main.py, generated .ts) to --file via load_standalone, resolve_source_location, or load_and_compile_standalone.","commonSituations":"Passing a generated client file (e.g. baml_client/.../main.py) instead of the source; passing baml.config or a manifest file; files renamed to .bak/.txt; forgetting the .baml extension on a newly created source file.","solutions":["Rename the file to have a `.baml` extension if it truly is BAML source.","Point --file at the actual `.baml` source file (e.g. baml_src/main.baml), not generated client code or config.","If you meant a whole project/config directory, use --project instead.","Check the canonical path printed in the error to identify which file was rejected."],"exampleFix":"// before\nbaml dev --file ./generated_baml_client.py\n\n// after\nbaml dev --file ./baml_src/main.baml","handlingStrategy":"validation","validationCode":"#!/usr/bin/env bash\nF=\"$1\"\ncase \"$F\" in\n  *.baml) ;;\n  *) echo \"--file requires a .baml source file, got: $F\"; exit 1 ;;\nesac","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only pass files ending in .baml to --file.","Don't confuse generated client code or config files with BAML sources.","Name new BAML source files with the .baml extension from the start."],"tags":["cli","baml","file","extension","unsupported-type"],"backgroundTag":"incompatible-source-type","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}