BoundaryML/baml · error
compilation failed: {e:?}
Error message
compilation failed: {e:?} What it means
During `baml generate`, after building the compiler database and symbol pool, the CLI fetches the compiled program bytecode via `db.get_bytecode(package)`. If the compiler produces any diagnostics/errors, they are formatted with `{e:?}` and wrapped in this "compilation failed" anyhow error.
Source
Thrown at baml_language/crates/baml_cli/src/generate.rs:350
eprintln!("add a generator section to `baml.toml`, for example:");
eprintln!();
eprintln!(" [generator.my_client]");
eprintln!(" output_type = \"python/pydantic\"");
eprintln!(" output_dir = \"../python\"");
eprintln!(" naming_convention = \"preserve-case\"");
}
return Ok(crate::ExitCode::Other);
}
let embedded_baml_toml = build_embedded_baml_toml(&from)?;
// Build the codegen SymbolPool from the compiler database.
let pool = baml_ide::build_symbol_pool(&db);
reporter.spin("Compiling", format!("{} file(s)", source_files.len()));
let program = db
.get_bytecode(package)
.map_err(|e| anyhow!("compilation failed: {e:?}"))?;
let baml_bytecode = baml_artifact::encode(baml_artifact::ArtifactKind::Program, &program)
.map_err(|e| anyhow!("failed to serialize BAML bytecode: {e}"))?;
let source_root = from.join("baml_src");
let user_baml_files = source_files
.iter()
.map(|source_file| {
let path = source_file.path(&db);
let relative_path = path
.strip_prefix(&source_root)
.or_else(|_| path.strip_prefix(&from))
.with_context(|| {
format!(
"BAML source {} is outside project root {}",
path.display(),
from.display()
)
})?;
Ok((View on GitHub (pinned to bd85ce9dee)
Solutions
- Read the detailed diagnostics after 'compilation failed:' and fix the reported BAML errors.
- Run `baml-cli fmt` / open the file in an editor with BAML LSP to locate the offending lines.
- Verify your generator block and clients in baml_src compile (e.g. via the VS Code BAML extension's diagnostics).
- Update the CLI if the errors mention unsupported syntax/features (version mismatch).
Example fix
// before (baml_src/generator.baml)
generator ClientGenerator { ... provider "baml-openai" } // typo'd provider
// after
generator ClientGenerator { ... provider "openai" } Defensive patterns
Strategy: try-catch
Try / catch
match baml_generate() {
Err(e) if e.to_string().starts_with("compilation failed") => {
eprintln!("Fix BAML diagnostics before generating: {e:#}");
std::process::exit(1);
}
Err(e) => return Err(e),
Ok(_) => {}
} Prevention
- Run the BAML LSP/VS Code extension to catch diagnostics before generating.
- Compile or fmt (baml-cli fmt) as a pre-commit gate in CI.
- Keep baml.toml and baml_src changes in the same commit.
- Pin the CLI version your project's BAML syntax targets.
When it happens
Trigger: `baml generate` on a project whose baml_src contains BAML source that does not compile — syntax errors, type errors, unresolved functions/clients, invalid generator config in baml.toml.
Common situations: A recent edit to a .baml file introduced an error; a generator block references a missing client; baml.toml and baml_src are out of sync; using new language features with an older CLI.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- {bail_context}
- compilation failed: {e:?}
- compilation failed: {e:?}
- no `.baml` files found in {}
- could not find packaged playground assets. For local debuggi
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/5c91301923cdc73d.
Report an issue: GitHub.