BoundaryML/baml · error · VmBamlError

baml.errors.InvalidArgument

baml.errors.InvalidArgument

Error message

invalid argument: {message}

What it means

An error value from the BAML standard library, mapping 1:1 to the `baml.errors.InvalidArgument` class. It is raised when a stdlib function receives an argument that is well-typed but has an unacceptable value or form for that operation.

Source

Thrown at baml_language/crates/bex_vm_types/src/errors.rs:113

    /// that does not match its declared `throws` contract `E`. Surfaces in
    /// BAML as `baml.panics.HostContractViolation`.
    ///
    /// `class_name` / `language` are populated when the violation arose from
    /// a host throw (echoing the offending host exception's identity) and
    /// `None` when it arose from a wrong-type return (no exception class to
    /// echo).
    #[error("host contract violation: {message} [class={class_name:?}, lang={language:?}]")]
    HostContractViolation {
        message: String,
        class_name: Option<String>,
        language: Option<String>,
    },
}

/// An error value from the BAML standard library. Maps 1:1 to a `baml.errors.*` class.
#[derive(Debug, Error, PartialEq, Clone)]
pub enum VmBamlError {
    #[error("invalid argument: {message}")]
    InvalidArgument { message: String },

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

    #[error("I/O error: {message}")]
    Io { message: String },

    #[error("timeout: {message}")]
    Timeout {
        message: String,
        duration_ms: Option<i64>,
    },

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

    #[error("access error: {message}")]

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Read the error message (the `message` field names the offending argument and reason) and correct the argument value at the call site.
  2. Validate arguments before calling the stdlib function (range checks, allowed-value lists).
  3. Check the function's documentation for accepted parameter values/types.
  4. Catch `baml.errors.InvalidArgument` in BAML to handle bad input from users gracefully.

Example fix

// before
let n = json.parseInt(str, 37); // invalid radix
// after
let n = json.parseInt(str, 16); // valid radix
Defensive patterns

Strategy: validation

Validate before calling

// BAML: validate arguments before the stdlib call
if radix < 2 || radix > 36 {
  return err("radix must be 2..36");
}

Try / catch

try {
  let n = std.parse_int(s, radix);
} catch e: baml.errors.InvalidArgument {
  return handle_bad_input(e.message);
}

Prevention

When it happens

Trigger: Calling a BAML stdlib function (string, JSON, math, etc.) with a parameter value it cannot accept — e.g. an out-of-domain numeric argument, an invalid mode/flag string, or a malformed input to a parsing function that specifically validates arguments.

Common situations: Hardcoded option strings that don't match accepted values; passing 0 or negative numbers where positive values are required; refactors that change argument order or semantics; translating examples from other languages with different stdlib contracts.

Understand the failure class

Background: "must be a positive integer", "cannot be empty", "invalid argument": how invalid-argument errors work across open-source libraries — this error's family across 33 libraries.

Related errors


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