BoundaryML/baml · error

{msg} at {:?}

Error message

{msg} at {:?}

What it means

The call to baml_vm::native::number_to_fixed(value, digits) returned an Err carrying a message (e.g. out-of-range digit count), which the interpreter re-wraps with the source span via anyhow::anyhow!("{msg} at {:?}"). This surfaces native numeric-formatting failures (typically digits outside the accepted range).

Source

Thrown at engine/baml-compiler/src/thir/interpret.rs:3013

                BamlValueWithMeta::Int(v, _) => *v as f64,
                _ => bail!(
                    "to_fixed() method only available on floats and ints at {:?}",
                    meta.0
                ),
            };

            if args.len() > 1 {
                bail!("to_fixed() method takes at most 1 argument at {:?}", meta.0);
            }

            let digits = match args.first() {
                Some(BamlValueWithMeta::Int(v, _)) => *v,
                Some(_) => bail!("to_fixed() digits argument must be an int at {:?}", meta.0),
                None => 0,
            };

            let formatted = baml_vm::native::number_to_fixed(value, digits)
                .map_err(|msg| anyhow::anyhow!("{msg} at {:?}", meta.0))?;
            Ok(BamlValueWithMeta::String(formatted, meta.clone()))
        }
        _ => bail!(
            "unknown method '{}' at {:?}, should have been caught during typechecking",
            method_name,
            meta.0
        ),
    }
}

#[cfg(test)]
mod tests {
    use std::path::PathBuf;

    #[allow(unused_imports)]
    use baml_types::ir_type::TypeIR;
    use internal_baml_ast::parse_standalone_expression;
    use internal_baml_diagnostics::{Diagnostics, SourceFile, Span};

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Clamp/validate the digits value before calling (e.g. ensure 0 <= digits <= 100)
  2. Read the wrapped {msg} in the error to see the native constraint violated
  3. Use a sane fixed precision such as 0–10 and guard dynamic values

Example fix

// before (unbounded dynamic digits)
let out = value.to_fixed(digits);
// after
let d = if digits < 0 { 0 } else if digits > 100 { 100 } else { digits };
let out = value.to_fixed(d);
Defensive patterns

Strategy: validation

Validate before calling

// clamp digits to a safe range before calling
if (d < 0 || d > 100) { d = 2; }

Try / catch

try { out = num.to_fixed(d); } catch (e) { log(e); out = num.to_fixed(2); }

Prevention

When it happens

Trigger: Calling to_fixed with an out-of-range or otherwise rejected digits value that the native number_to_fixed implementation rejects (e.g. negative or excessively large digit counts, depending on the native bounds).

Common situations: Computing digits dynamically from data or LLM output so the value lands outside the accepted range at runtime; hardcoding an unusual precision like to_fixed(100).

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


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