BoundaryML/baml · error

: expected float at index , got

Error message

{fn_name}: expected float at index {index}, got {}

What it means

Panic in expect_float when a validated float[] element has no object pointer at all (e.g. an unboxed or null-tagged value). FloatStats/Summable methods are declared on float[] and elements should already be boxed Float objects; any other tag is an upstream invariant violation.

Solutions

  1. Rebuild the array with explicit float elements before calling sum/median.
  2. Check that the value bound to the float[] is genuinely a float[] and not a subtype/mixed array.
  3. Report to maintainers — validated float[] elements must be boxed floats.
Defensive patterns

Strategy: type-guard

Validate before calling

// before calling float stats
if (!arr.every(v => typeof v === 'number')) throw new Error('expected float[] elements');

Type guard

const isFloatArray = (a) => Array.isArray(a) && a.every(v => typeof v === 'number');

Prevention

When it happens

Trigger: Invoking sum or median on a float[] where an element is not a heap-allocated Float object (missing object pointer) — e.g. array contents corrupted or mis-typed upstream.

Common situations: Calling float-array statistics methods on arrays built through unchecked paths, aliasing bugs, or VM type-checker gaps.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


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

Appendix: source

Thrown at baml_language/crates/bex_vm/src/package_baml/root.rs:937

    if value.as_bool().is_some() {
        return "bool".to_string();
    }
    if value.is_omitted() {
        return "omitted".to_string();
    }
    if let Some(ptr) = value.as_object_ptr() {
        return ObjectType::of(vm.get_object(ptr)).to_string();
    }
    "unknown".to_string()
}

/// Extracts a float from a validated `float[]` element. The `FloatStats` /
/// `Summable` methods are declared on `float[]`, so by the time execution reaches
/// the native path each element is a boxed float; any other tag is an upstream
/// invariant violation.
fn expect_float(vm: &BexVm, value: Value, fn_name: &str, index: usize) -> f64 {
    let Some(ptr) = value.as_object_ptr() else {
        unreachable!(
            "{fn_name}: expected float at index {index}, got {}",
            value_type_name(vm, value)
        );
    };
    match vm.get_object(ptr) {
        Object::Float(float) => *float,
        _ => unreachable!(
            "{fn_name}: expected float at index {index}, got {}",
            value_type_name(vm, value)
        ),
    }
}

/// Extracts an `i64` from a validated `int[]` element. Ints are unboxed tagged
/// values, so no heap read is needed; a missing int tag is an upstream invariant
/// violation.
fn expect_int(value: Value, fn_name: &str, index: usize) -> i64 {
    value

View on GitHub (pinned to bd85ce9dee)