BoundaryML/baml · error · RuntimeError

{message}

Error message

{message}

What it means

RuntimeError::Compilation is raised when the BAML source fails to compile at runtime: the `message` field carries the compiler's diagnostic text. This is distinct from engine/runtime failures — it means the source itself could not be compiled into an executable form.

Source

Thrown at baml_language/crates/bex_project/src/lib.rs:94

impl From<IndexMap<String, BexExternalValue>> for BexArgs {
    fn from(required: IndexMap<String, BexExternalValue>) -> Self {
        Self {
            required,
            optional: IndexMap::new(),
        }
    }
}

/// Errors that can occur during runtime operations.
#[derive(Debug, Error)]
pub enum RuntimeError {
    #[error("{0}")]
    Other(String),

    #[error("Invalid argument: {name}")]
    InvalidArgument { name: String },

    #[error("{message}")]
    Compilation { message: String },

    #[error("{0}")]
    Engine(#[from] bex_engine::EngineError),

    #[error("Failed to convert result to owned value: {0}")]
    Access(#[from] bex_heap::AccessError),
}

/// True iff `err` wraps an engine cancellation panic.
///
/// Centralizes the cancellation-classification logic that bridges and the
/// LSP server need to distinguish cancellation from other runtime errors.
pub fn is_cancelled_runtime_error(err: &RuntimeError) -> bool {
    matches!(err, RuntimeError::Engine(e) if is_cancelled_engine_error(e))
}

/// Compile a BAML project from in-memory sources and initialize a runtime.

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Read the `message` diagnostic, fix the BAML source error it points to, and recompile.
  2. Validate the BAML file with the CLI/compiler in isolation to get precise line/column errors.
  3. Check for renamed or removed language constructs after upgrading the baml library.
  4. If BAML is generated at runtime, add generation-time validation to catch malformed output before compilation.

Example fix

// before
let src = "function Foo() { ..."; // unbalanced brace
project.compile(src)?; // RuntimeError::Compilation
// after
let src = "function Foo() { \"ok\" }";
project.compile(src)?;
Defensive patterns

Strategy: validation

Validate before calling

// Compile-check BAML source before the runtime call
let diag = baml_cli::check(source_path)?; // or run `baml-cli check`
if !diag.is_empty() {
    eprintln!("fix BAML errors first: {diag:#?}");
    return Ok(());
}

Type guard

fn is_compilation_error(err: &RuntimeError) -> Option<&str> {
    if let RuntimeError::Compilation { message } = err { Some(message) } else { None }
}

Try / catch

match project.compile(src) {
    Err(RuntimeError::Compilation { message }) => {
        eprintln!("BAML compilation failed:\n{message}");
        // show diagnostics to the user / abort pipeline
    }
    other => other?,
}

Prevention

When it happens

Trigger: Calling bex_project APIs that compile BAML source (e.g. loading/compiling a project or string of BAML) when the source contains syntax errors, unknown types/functions, or otherwise fails type/borrow checking in the compiler.

Common situations: Copy-pasted BAML with syntax mistakes; referencing functions/types that don't exist or were renamed; using syntax unsupported by the installed library version; dynamically generated BAML with interpolation errors.

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/9eb86548eda7c9a0. Report an issue: GitHub.