BoundaryML/baml · error · VmPanic
baml.panics.InvalidFieldAccess
baml.panics.InvalidFieldAccess
Error message
invalid field access: field {field_index} of {field_count} What it means
Raised when a VM field access targets a field index that does not exist on the value being accessed. The error reports the field index requested and the number of fields the record actually has. It indicates the accessor and the record shape are out of sync.
Source
Thrown at baml_language/crates/bex_vm_types/src/errors.rs:39
/// `ThrowIfPanic` instruction filters which panics are caught vs rethrown.
#[derive(Debug, Error, PartialEq, Clone)]
pub enum VmPanic {
#[error("division by zero: {left:?} / {right:?}")]
DivisionByZero { left: Value, right: Value },
/// An `int` (i63) arithmetic operation overflowed the representable
/// range `[INT_MIN, INT_MAX]`. Carries a human-readable description of
/// the operation (e.g. `"4611686018427387903 + 1"`); built only on the
/// cold overflow path, so the `String` alloc never touches hot code.
#[error("integer overflow: {message}")]
IntegerOverflow { message: String },
// Raised by array and byte-array subscripting, so the message stays generic
// ("index", not "array index").
#[error("index out of bounds: {index} of {length}")]
IndexOutOfBounds { index: i64, length: usize },
#[error("invalid field access: field {field_index} of {field_count}")]
InvalidFieldAccess {
field_index: usize,
field_count: usize,
},
#[error("key not found in map")]
MapKeyNotFound,
#[error("stack overflow")]
StackOverflow,
#[error("assertion failed")]
AssertionFailed,
#[error("unreachable code executed")]
Unreachable,
#[error("operation cancelled")]View on GitHub (pinned to bd85ce9dee)
Solutions
- Recompile the BAML program so field indices match the current record layout.
- Verify the value being accessed actually is the intended record type before field access.
- Catch `baml.panics.InvalidFieldAccess` if dynamic/reflection-style access is intentional.
Example fix
// before // compiled bytecode for old schema: field index 5 no longer exists // after // regenerate bytecode from the updated .baml schema, then re-run
Defensive patterns
Strategy: type-guard
Validate before calling
// BAML: confirm the value has the expected field count before access
if (record.field_count() <= FIELD_IDX) { return err("stale schema?"); } Type guard
// BAML: narrow before field access
if (is_my_record(v)) { return v.expected_field; } Try / catch
// BAML
try {
let f = record.field(FIELD_IDX);
} catch (e: baml.panics.InvalidFieldAccess) {
return err("record layout mismatch");
} Prevention
- Recompile after every schema change; never mix old bytecode with new records
- Validate record types at boundaries before field access
- Avoid reaching into reflection internals directly
When it happens
Trigger: Accessing a struct/record field by index where the index exceeds the record's field_count, typically from compiled field access instructions against a record of a different/older layout (e.g. after a schema change or accessing a field on the wrong type).
Common situations: Running cached/compiled artifacts after the schema changed (fields added/removed/reordered), reflection over records with stale type info, accessing a field on a record type that was never validated at compile time.
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
- baml.panics.IntegerOverflow
- baml.panics.IndexOutOfBounds
- baml.panics.MapKeyNotFound
- baml.panics.StackOverflow
- baml.panics.AssertionFailed
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/15548ac1af8ef6d0.
Report an issue: GitHub.