BoundaryML/baml · error

to_fixed() method takes at most 1 argument at {:?}

Error message

to_fixed() method takes at most 1 argument at {:?}

What it means

The "to_fixed" method accepts at most 1 argument (the number of digits). The interpreter bails when more than one argument is passed, reporting the source span. Digits is optional and defaults to 0 when omitted.

Source

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

                    meta.0
                );
            };
            // Replace first occurrence only (matching JavaScript behavior)
            let result = s.replacen(search.as_str(), replacement.as_str(), 1);
            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
        ),
    }

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Pass at most one integer argument: the digit count (0–N)
  2. Remove extra arguments; rounding/formatting options are not supported here
  3. Use 0 arguments to round to integer formatting by default

Example fix

// before
let out = price.to_fixed(2, "usd");
// after
let out = price.to_fixed(2);
Defensive patterns

Strategy: validation

Validate before calling

// at most 1 arg: num.to_fixed(digits?) — drop extras

Try / catch

try { out = num.to_fixed(d); } catch (e) { log("to_fixed arity: " + e); }

Prevention

When it happens

Trigger: Calling num.to_fixed(2, true), to_fixed(2, "round"), or any call with 2+ arguments — usually a misunderstanding of the signature (digits only).

Common situations: Porting from languages with richer formatting APIs (e.g. Python format specs, Intl.NumberFormat options objects) and trying to pass options as extra parameters.

Understand the failure class

Background: "must be a positive integer", "cannot be empty", "invalid argument": how invalid-argument errors work across open-source libraries — this error's family across 33 libraries.

Related errors


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