BoundaryML/baml · error · CtypesError

Invalid decimal bigint literal ({len} bytes)

Error message

Invalid decimal bigint literal ({len} bytes)

What it means

CtypesError::InvalidBigintLiteral { len } is raised when a decimal type literal in a descriptor exceeds the accepted form/size. Like InvalidBigint, it carries only the byte length, so a hostile descriptor cannot amplify logs by echoing its full payload (per the source doc comment). It means the decimal literal string itself was not a valid/acceptable bigint literal.

Source

Thrown at baml_language/crates/bridge_ctypes/src/error.rs:28

    #[error("Null buffer pointer")]
    NullBuffer,

    #[error("Invalid handle key: {0}")]
    InvalidHandleKey(u64),

    #[error("Map entry missing key")]
    MapEntryMissingKey,

    /// Carries only the input length, not the input itself — untrusted hex
    /// blobs can be up to the FFI decode cap (~67M chars), and embedding
    /// them in error messages bloats logs and exposes payload contents.
    #[error("Invalid bigint hex string ({len} bytes)")]
    InvalidBigint { len: usize },

    /// Carries only the input length for over-cap decimal type literals, so a
    /// hostile descriptor cannot amplify logs by echoing its full payload.
    #[error("Invalid decimal bigint literal ({len} bytes)")]
    InvalidBigintLiteral { len: usize },

    #[error(
        "Invalid InboundValue.value_type: a root union or optional does not identify one exact selected type"
    )]
    InvalidInboundValueTypeRootUnion,

    #[error("Union selected type `{selected}` is not a member of declared union `{union}`")]
    UnionSelectedTypeNotMember { selected: String, union: String },

    #[error("Internal error: {0}")]
    InternalError(String),
}

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Keep decimal literals within the bridge's cap; reject oversized literals host-side before the call.
  2. Validate the literal is pure decimal digits (optional sign) before sending.
  3. Clamp precision/scale parameters to sane ranges when generating descriptors.
  4. Treat repeated occurrences as hostile input and log only the length, as the library does.

Example fix

// before
literal = digits.repeat(10_000_000)  # over cap -> InvalidBigintLiteral
send_descriptor(literal)
// after
if len(literal) > MAX_LITERAL_BYTES: raise ValueError("decimal literal too large")
send_descriptor(literal)
Defensive patterns

Strategy: validation

Validate before calling

MAX_LITERAL = 4096
def ensure_decimal_literal(lit: str):
    body = lit[1:] if lit[:1] in "+-" else lit
    if not body.isdigit() or len(lit) > MAX_LITERAL:
        raise ValueError("decimal literal invalid or over cap")

Try / catch

try:
    send_descriptor(literal)
except BridgeError as e:
    if "Invalid decimal bigint literal" in str(e):
        raise ValueError(f"reject decimal literal of length {len(literal)}") from e
    raise

Prevention

When it happens

Trigger: Supplying a type descriptor (e.g. for decimal/precision types) whose literal digits are malformed or over the cap — a decimal literal with invalid characters or an over-cap number of digits.

Common situations: Dynamically generated descriptors with user-supplied precision/scale values; copy-pasted descriptors with stray characters; fuzz or hostile descriptors pushing oversized literals across FFI.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


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