BoundaryML/baml · error

index not int at

Error message

index not int at {:?}

What it means

When indexing a list, the interpreter requires the index expression to evaluate to BamlValueWithMeta::Int. A non-integer index (string, float, bool) throws "index not int at {:?}". List indices must be integer expressions.

Solutions

  1. Convert the index to an integer before indexing (parse the string, truncate/round the float)
  2. If using string keys, use a map instead of a list
  3. Trace where the index value originates (likely an untyped LLM/string output) and add an explicit int conversion
  4. Validate the index is an integer at authoring time

Example fix

// before
let item = items[idx_str] // idx_str is "2"
// after
let item = items[idx_str.parse_int()]
Defensive patterns

Strategy: validation

Validate before calling

// Coerce/validate the index to an integer before list access
function toIntIndex(v: unknown): number {
  const n = typeof v === "string" ? parseInt(v, 10) : v;
  if (typeof n !== "number" || !Number.isInteger(n)) throw new Error("List index must be an int");
  return n;
}

Type guard

function isIntIndex(v: unknown): v is number {
  return typeof v === "number" && Number.isInteger(v);
}

Try / catch

try {
  return evalBaml(indexExpr);
} catch (e) {
  if (String(e).includes("index not int")) {
    throw new Error("List index is not an integer — parse/convert it before indexing");
  }
  throw e;
}

Prevention

When it happens

Trigger: `list[idx]` where idx evaluates to a string (e.g. from user/LLM output), a float, or any non-Int value.

Common situations: Passing a string index that came from parsed text or an LLM response without converting it; using a float computed by division; using map-style string keys on a list.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


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

Appendix: source

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

                )?;
                let i = expect_value(
                    evaluate_expr(
                        index,
                        scopes,
                        thir,
                        run_llm_function,
                        watch_handler,
                        function_name,
                    )
                    .await?,
                )?;
                let arr = match b.clone() {
                    BamlValueWithMeta::List(v, _) => v,
                    _ => bail!("array access on non-list at {:?}", meta),
                };
                let idx = match i {
                    BamlValueWithMeta::Int(ii, _) => ii as usize,
                    _ => bail!("index not int at {:?}", meta),
                };
                let v = arr.get(idx).cloned().context("index out of bounds")?;
                EvalValue::Value(v.clone())
            }
            Expr::FieldAccess { base, field, meta } => {
                let b = expect_value(
                    evaluate_expr(
                        base,
                        scopes,
                        thir,
                        run_llm_function,
                        watch_handler,
                        function_name,
                    )
                    .await?,
                )?;
                match b.clone() {
                    BamlValueWithMeta::Map(m, _) => {

View on GitHub (pinned to bd85ce9dee)