BoundaryML/baml · error · VmBamlError

parse error: {message}

Error message

parse error: {message}

What it means

An error value from the BAML standard library, mapping to the `baml.errors.ParseError` class. It is raised when a stdlib parsing function cannot interpret its input — the input is well-formed as a value of the right type but does not conform to the expected grammar.

Source

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

    /// `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}")]
    AccessError { message: String },

    #[error("render prompt: {message}")]

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Inspect the `message` for the parse failure position/reason and fix the input or its format.
  2. Validate/normalize input (strip whitespace/code fences) before parsing; for LLM output use a robust extraction step.
  3. Catch `baml.errors.ParseError` and provide a fallback parse path or a retry with a stricter prompt.
  4. Check version-specific format expectations (e.g. date formats) and use explicit format arguments when supported.

Example fix

// before
let v = json.parse(response.text); // text may be "```json\n{...}\n```"
// after
let v = json.parse(strip_code_fence(response.text));
Defensive patterns

Strategy: try-catch

Validate before calling

// BAML: quick sanity check before parsing
if !trimmed.startsWith("{") {
  return err("not a JSON object");
}

Try / catch

try {
  let v = json.parse(text);
} catch e: baml.errors.ParseError {
  return try_lax_parse(text) ?? report_parse_failure(e.message);
}

Prevention

When it happens

Trigger: Calling stdlib parsers (e.g. JSON parse, datetime parse, number parse) with a string that does not match the expected syntax; the message details where/why parsing failed.

Common situations: Feeding LLM-generated text (often slightly malformed JSON) into parsers; user-supplied dates or numbers with unexpected formats; log/config formats that changed between versions.

Understand the failure class

Background: JSON parse error: "Unexpected token" / "not valid JSON" / "failed to parse" — what JSON parsers are really complaining about — this error's family across 45 libraries.

Related errors


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