BoundaryML/baml · error

{bail_context}

Error message

{bail_context}

What it means

Project diagnostics reported compilation errors, so the command aborts by rendering the diagnostics to stderr and bailing with the caller-supplied context message (`bail_context`). It is a generic wrapper: the real details are in the rendered diagnostics above the message.

Source

Thrown at baml_language/crates/baml_cli/src/run_command.rs:348

    fn render_and_bail_on_errors(
        &self,
        diagnostics: &[baml_db::baml_compiler_diagnostics::Diagnostic],
        db: &ProjectDatabase,
        bail_context: &str,
        reporter: &Reporter,
    ) -> Result<()> {
        let errors: Vec<_> = diagnostics
            .iter()
            .filter(|d| d.severity == Severity::Error)
            .cloned()
            .collect();
        if errors.is_empty() {
            return Ok(());
        }
        let rendered = crate::check_command::render_project_diagnostics(db, &errors);
        reporter.abandon();
        eprintln!("{rendered}");
        anyhow::bail!("{bail_context}");
    }

    /// Compile `db` to bytecode and build a `BexEngine`.
    fn compile_to_engine(
        &self,
        db: &ProjectDatabase,
        package: SourceRoot,
        argv: Vec<String>,
    ) -> Result<BexEngine> {
        let bytecode = baml_compiler2_emit::generate_project_bytecode(db, package)
            .map_err(|e| anyhow!("compilation failed: {e:?}"))?;
        BexEngine::new_with_runtime_compiler(
            bytecode,
            Arc::new(sys_native::SysOps::native()),
            argv,
            bex_project::runtime_compiler(),
        )
        .map_err(|e| anyhow!("failed to create engine: {e:?}"))

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Read the rendered diagnostics printed above the bail message and fix the reported `.baml` errors
  2. Run `baml check` to see the full diagnostic list
  3. Fix type/name errors in the offending `.baml` source files

Example fix

// before
function Foo(x: int32) { ... }  // unknown type int32
// after
function Foo(x: int) { ... }
Defensive patterns

Strategy: try-catch

Validate before calling

const diags = await baml.check(projectDir);
const errors = diags.filter(d => d.severity === 'error');
if (errors.length) { console.error(baml.renderDiagnostics(diags)); process.exit(1); }

Try / catch

try { await baml.loadAndCompile(dir); } catch (e) { console.error(e.message); // rendered diagnostics were already on stderr
  process.exit(1); }

Prevention

When it happens

Trigger: `render_and_bail_on_errors` is called by `check_project_diagnostics`, `load_and_compile`, or `run_expression` and the error list from the project database is non-empty.

Common situations: Syntax or type errors in `.baml` files; referencing unknown functions/classes; broken imports — surfaced during `baml check`, `baml run`, or expression evaluation.

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


AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12). Data as JSON: /api/errors/5300d35a0410b26e. Report an issue: GitHub.