BoundaryML/baml · error
to_fixed() digits argument must be an int at
Error message
to_fixed() digits argument must be an int at {:?} What it means
When to_fixed receives an argument, it must be an Int (the number of decimal digits). The interpreter matches args.first() and bails on any non-Int value (float, string, bool, null, etc.), reporting the source span.
Solutions
- Pass an integer literal or an Int-typed variable for digits
- Convert a float digits value to int before calling (e.g. truncate/round)
- Default to omitting the argument (0 digits) if no meaningful count is available
Example fix
// before (digits came from LLM as float) let out = value.to_fixed(digits); // after let out = value.to_fixed(digits.ToInt());
Defensive patterns
Strategy: type-guard
Validate before calling
// digits must be int: if (d is int) { num.to_fixed(d); } Type guard
fn is_int(v: Value) -> bool { matches!(v, Value::Int(_)) } Try / catch
try { out = num.to_fixed(d); } catch (e) { out = num.to_fixed(0); } Prevention
- Use integer literals for precision
- Truncate float digit counts first
- Ensure dynamic digits come from int-typed fields
When it happens
Trigger: Calling num.to_fixed("2"), to_fixed(2.0), to_fixed(someString), or passing null where the digits count should be.
Common situations: A digits value computed from LLM output that came back as a float or string; copying code where 2 was written but a variable holding a float was substituted.
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
- replace() replacement argument must be a string at
- replace() search argument must be a string at
- to_fixed() method only available on floats and ints at
- baml.fetch_as: expected baml.fetch_as arg to be a string or…
- baml.json.serialize returned non-string value
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/20dc850ca2f6b5a7.
Report an issue: GitHub.
Appendix: source
Thrown at engine/baml-compiler/src/thir/interpret.rs:3008
Ok(BamlValueWithMeta::String(result, meta.clone()))
}
"to_fixed" => {
let value = match receiver {
BamlValueWithMeta::Float(v, _) => *v,
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;View on GitHub (pinned to bd85ce9dee)