{"record":{"id":"506745b195e8440a","repo":"BoundaryML/baml","slug":"cannot-derive-an-output-name-from-pass-o-path-to-name-the","errorCode":null,"errorMessage":"cannot derive an output name from `{}`; pass `-o <PATH>` to name the output.","messagePattern":"cannot derive an output name from `(.+?)`; pass `-o <PATH>` to name the output\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"baml_language/crates/baml_cli/src/pack_command.rs","lineNumber":433,"sourceCode":"    ///   `foo`). `baml.toml` isn't consulted — single-file packs are\n    ///   intentionally hermetic.\n    /// - Project mode: `[package].name` from `<from>/baml.toml` when a\n    ///   manifest is present, else the project directory name for a\n    ///   manifest-less `baml_src/` project (see\n    ///   [`crate::project_load::resolve_project_name`]).\n    fn resolve_output_basename(&self) -> Result<String> {\n        if let Some(file) = self.file.as_deref() {\n            // Keep `--file` hermetic: derive the name from the file path\n            // alone, never from `--from`/project markers. A path with no\n            // usable file-name component (no stem, e.g. `..`, or a non-UTF-8\n            // name) can't be named automatically — bail rather than leak the\n            // cwd's project context into a single-file pack.\n            return file\n                .file_stem()\n                .and_then(|s| s.to_str())\n                .map(str::to_string)\n                .ok_or_else(|| {\n                    anyhow::anyhow!(\n                        \"cannot derive an output name from `{}`; pass `-o <PATH>` to name the output.\",\n                        file.display()\n                    )\n                });\n        }\n        crate::project_load::resolve_project_name(self.from.as_deref())\n    }\n}\n\n/// Resolve a single function-name string against the engine; returns\n/// canonical qualified/display/subcommand-name triple.\nfn resolve_one(engine: &BexEngine, func: &str) -> Result<ResolvedPackTarget> {\n    if !engine.function_exists(func) {\n        let suggestions = function_suggestions(engine, func);\n        if suggestions.is_empty() {\n            anyhow::bail!(\n                \"function `{func}` not found. Use `baml run --list` to see \\\n                 available targets.\"","sourceCodeStart":415,"sourceCodeEnd":451,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/baml_cli/src/pack_command.rs#L415-L451","documentation":"resolve_output_basename derives the output file name for the packed binary. For single-file `--file` packs it uses the file stem; if the path has no usable UTF-8 stem (e.g. a nameless/odd path), and no `-o <PATH>` was supplied, the CLI cannot name the output and bails, telling you to pass `-o` explicitly.","triggerScenarios":"Running `baml pack --file <path>` where `<path>` yields no valid file_stem (non-UTF-8 or empty stem) without specifying `-o`.","commonSituations":"Programmatically constructed paths with unusual characters or non-UTF-8 bytes; piping a path from another tool on systems with odd filenames; forgetting `-o` on scripted pack invocations.","solutions":["Pass `-o <PATH>` to name the output explicitly, e.g. `baml pack --file ./weird\\ name.baml -o out`.","Rename the source file so it has a normal UTF-8 stem, then re-run without `-o`.","For project packs, ensure the project root resolves to a valid project name (resolve_project_name) or supply `-o`."],"exampleFix":"// before\nbaml pack --file \"$(printf 'weird\\xff.baml')\"\n\n// after\nbaml pack --file ./my_func.baml -o my_func_bin","handlingStrategy":"validation","validationCode":"# always supply -o when the input path is not a simple UTF-8 name\ncase \"$FILE\" in\n  *[![:print:]]*|\"\") echo \"use -o to name output\" >&2; OUT=(-o packed_bin) ;;\n  *) OUT=() ;;\nesac\nbaml pack --file \"$FILE\" \"${OUT[@]}\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass `-o` in scripted/automated pack invocations.","Keep source filenames simple ASCII stems.","Validate file paths coming from other tools before packing."],"tags":["cli","output-naming","baml-pack"],"backgroundTag":"missing-required-flag","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"}