BoundaryML/baml · error
`--file` and `--project` are mutually exclusive; `--file` al
Error message
`--file` and `--project` are mutually exclusive; `--file` already names the single source to load.
What it means
validate_file_project_flags enforces that `--file` and `--project` are mutually exclusive: both select a source location, and `--file` already means 'load exactly this one file'. Passing both is ambiguous, so the CLI refuses the invocation up front.
Source
Thrown at baml_language/crates/baml_cli/src/project_load.rs:26
use crate::reporter::Reporter;
/// The source location shape shared by `run`, `pack`, and `playground`.
#[derive(Debug, Clone, PartialEq, Eq)]
pub(crate) enum SourceLocation {
/// A resolved BAML project root discovered by walking up from `from` or cwd.
Project { root: PathBuf, files: Vec<PathBuf> },
/// A hermetic single-file source selected through `--file`.
StandaloneFile { file: PathBuf, root: PathBuf },
}
/// `--file` and `--project` both name a source location.
pub(crate) fn validate_file_project_flags(
file: Option<&Path>,
project: Option<&Path>,
) -> Result<()> {
if file.is_some() && project.is_some() {
anyhow::bail!(
"`--file` and `--project` are mutually exclusive; `--file` already names \
the single source to load."
);
}
Ok(())
}
/// Resolve the CLI source location exactly like `baml run` project/file mode.
pub(crate) fn resolve_source_location(
from: Option<&Path>,
file: Option<&Path>,
reporter: Option<&Reporter>,
) -> Result<SourceLocation> {
validate_file_project_flags(file, from)?;
if let Some(file) = file {
let canonical = resolve_standalone_file(file)?;
let root = canonicalView on GitHub (pinned to bd85ce9dee)
Solutions
- Remove --project and keep only --file to compile/test a single standalone file.
- Remove --file and keep only --project to load the whole project.
- If a wrapper script adds --project conditionally, gate it so it's omitted whenever --file is supplied.
Example fix
// before baml dev --project ./baml_src --file ./baml_src/main.baml // after baml dev --file ./baml_src/main.baml
Defensive patterns
Strategy: validation
Validate before calling
#!/usr/bin/env bash
EXTRA=()
[ -n "$FILE" ] && EXTRA+=(--file "$FILE")
[ -z "$FILE" ] && [ -n "$PROJECT" ] && EXTRA+=(--project "$PROJECT")
baml dev "${EXTRA[@]}" Prevention
- Never hardcode --project in wrapper scripts that also accept --file.
- Decide per invocation: single file → --file only; whole project → --project only.
- Add a shell alias guard that errors when both variables are set.
When it happens
Trigger: Any CLI command (baml dev/test/validate via validate_flags, resolve_source_location, run_with_reporter, or test_run_allows_file_with_omitted_from) invoked with both a --file path and a --project path set at the same time.
Common situations: Shell scripts accumulating flags where --project is always passed and --file is appended conditionally; copying an example command line and adding --file; an alias wrapping the command with --project baked in.
Understand the failure class
Background: "mutually exclusive" flag errors: what "can't supply both nx and xx", "--raw is not compatible with -i" and "cannot be used with" mean, and how to fix them — this error's family across 29 libraries.
Related errors
- `--sdk-import-path` is only valid for the Go generator
- compilation failed: {e:?}
- expression mode (`-e` / `--expression`) is not packageable;
- positional `<TARGET>` is a function name, not a file path. F
- no `.baml` files found in {}
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/e4598317bc2d5406.
Report an issue: GitHub.