{"record":{"id":"60acccf8adf0c37a","repo":"BoundaryML/baml","slug":"invalid-weight-format-expected-name-weight","errorCode":null,"errorMessage":"Invalid weight format: '{}'. Expected 'name=weight'","messagePattern":"Invalid weight format: '(.+?)'\\. Expected 'name=weight'","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-runtime/src/optimize/pareto.rs","lineNumber":401,"sourceCode":"\n/// Parse weight arguments from CLI (e.g., \"accuracy=0.8,tokens=0.2\")\npub fn parse_weight_args(weight_args: &[String]) -> Result<Vec<Objective>> {\n    if weight_args.is_empty() {\n        // Default: optimize accuracy only\n        return Ok(vec![Objective {\n            name: \"accuracy\".to_string(),\n            weight: 1.0,\n            direction: Direction::Maximize,\n        }]);\n    }\n\n    let mut objectives = Vec::new();\n\n    for arg in weight_args {\n        for part in arg.split(',') {\n            let parts: Vec<&str> = part.split('=').collect();\n            if parts.len() != 2 {\n                anyhow::bail!(\"Invalid weight format: '{}'. Expected 'name=weight'\", part);\n            }\n\n            let name = parts[0].trim();\n            let weight: f64 = parts[1]\n                .trim()\n                .parse()\n                .with_context(|| format!(\"Invalid weight value: '{}'\", parts[1]))?;\n\n            let direction = match name {\n                \"accuracy\" => Direction::Maximize,\n                \"tokens\" | \"prompt_tokens\" | \"completion_tokens\" | \"latency\" => Direction::Minimize,\n                name if name.starts_with(\"check:\") => Direction::Maximize,\n                _ => anyhow::bail!(\n                    \"Unknown objective: '{}'. Valid objectives: accuracy, tokens, prompt_tokens, completion_tokens, latency, check:<name>\",\n                    name\n                ),\n            };\n","sourceCodeStart":383,"sourceCodeEnd":419,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-runtime/src/optimize/pareto.rs#L383-L419","documentation":"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.","triggerScenarios":"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,`.","commonSituations":"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.","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)."],"exampleFix":"// before\nbaml optimize --weights accuracy 0.5 latency\n// after\nbaml optimize --weights \"accuracy=0.5,latency=0.5\"","handlingStrategy":"validation","validationCode":"// Shell pre-check for each weight argument\nfor w in $WEIGHTS; do\n  case \"$w\" in\n    *=*) n=\"${w%%=*}\"; v=\"${w##*=}\";\n      [[ \"$n\" == *\"=\"* || -z \"$n\" || -z \"$v\" ]] && { echo \"bad weight: $w\"; exit 1; } ;;\n    *) echo \"bad weight (needs name=weight): $w\"; exit 1 ;;\n  esac\ndone","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["cli","argument-parsing","format","optimizer"],"backgroundTag":"invalid-argument-format","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}