BoundaryML/baml · error
Invalid weight format
Error message
Invalid weight format: '{}'. Expected 'name=weight' What it means
The Pareto optimizer's `parse_weight_args` parses objective weight arguments of the form `name=weight`. Each argument (and each comma-separated part) must contain exactly one `=`; anything else (no `=`, multiple `=`, or an empty string) is rejected with this message.
Solutions
- Write each objective as `name=weight` with exactly one `=`, e.g. `--weights accuracy=0.6,latency=0.4`.
- Remove extra `=` characters and empty comma segments; quote the argument so the shell preserves it.
- Ensure the weight value itself is a parseable f64 (see the related 'Invalid weight value' error).
Example fix
// before baml optimize --weights accuracy 0.5 latency // after baml optimize --weights "accuracy=0.5,latency=0.5"
Defensive patterns
Strategy: validation
Validate before calling
// Shell pre-check for each weight argument
for w in $WEIGHTS; do
case "$w" in
*=*) n="${w%%=*}"; v="${w##*=}";
[[ "$n" == *"="* || -z "$n" || -z "$v" ]] && { echo "bad weight: $w"; exit 1; } ;;
*) echo "bad weight (needs name=weight): $w"; exit 1 ;;
esac
done Prevention
- Always quote --weights arguments so `=` and commas survive shell parsing.
- Keep a canonical example (`accuracy=0.6,latency=0.4`) in your project docs/scripts.
- Avoid trailing commas in the weights list.
When it happens
Trigger: Passing a weight argument to the optimizer CLI without exactly one `=`, e.g. `--weights accuracy` or `--weights accuracy=0.5=extra`, or an empty segment from a trailing comma like `accuracy=1,`.
Common situations: Typing `--weights "accuracy 0.5"` with a space instead of `=`; quoting mistakes in the shell dropping the `=`; copying objective names from docs without the weight portion.
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
- are mutually exclusive dispatch modes — pick one.
- script body has `--function` without a value
- unexpected token ` ` in script body. Script bodies have the…
- Unknown objective: ' '. Valid objectives: accuracy, tokens…
- unknown run-verb flag
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/60acccf8adf0c37a.
Report an issue: GitHub.
Appendix: source
Thrown at engine/baml-runtime/src/optimize/pareto.rs:401
/// Parse weight arguments from CLI (e.g., "accuracy=0.8,tokens=0.2")
pub fn parse_weight_args(weight_args: &[String]) -> Result<Vec<Objective>> {
if weight_args.is_empty() {
// Default: optimize accuracy only
return Ok(vec![Objective {
name: "accuracy".to_string(),
weight: 1.0,
direction: Direction::Maximize,
}]);
}
let mut objectives = Vec::new();
for arg in weight_args {
for part in arg.split(',') {
let parts: Vec<&str> = part.split('=').collect();
if parts.len() != 2 {
anyhow::bail!("Invalid weight format: '{}'. Expected 'name=weight'", part);
}
let name = parts[0].trim();
let weight: f64 = parts[1]
.trim()
.parse()
.with_context(|| format!("Invalid weight value: '{}'", parts[1]))?;
let direction = match name {
"accuracy" => Direction::Maximize,
"tokens" | "prompt_tokens" | "completion_tokens" | "latency" => Direction::Minimize,
name if name.starts_with("check:") => Direction::Maximize,
_ => anyhow::bail!(
"Unknown objective: '{}'. Valid objectives: accuracy, tokens, prompt_tokens, completion_tokens, latency, check:<name>",
name
),
};
View on GitHub (pinned to bd85ce9dee)