{"record":{"id":"995c2c88251b71a8","repo":"BoundaryML/baml","slug":"unknown-objective-valid-objectives-accuracy-tokens-prompt","errorCode":null,"errorMessage":"Unknown objective: '{}'. Valid objectives: accuracy, tokens, prompt_tokens, completion_tokens, latency, check:<name>","messagePattern":"Unknown objective: '(.+?)'\\. Valid objectives: accuracy, tokens, prompt_tokens, completion_tokens, latency, check:<name>","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-runtime/src/optimize/pareto.rs","lineNumber":414,"sourceCode":"\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\n            objectives.push(Objective {\n                name: name.to_string(),\n                weight,\n                direction,\n            });\n        }\n    }\n\n    // Ensure accuracy is included\n    if !objectives.iter().any(|o| o.name == \"accuracy\") {\n        objectives.insert(\n            0,\n            Objective {","sourceCodeStart":396,"sourceCodeEnd":432,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-runtime/src/optimize/pareto.rs#L396-L432","documentation":"`parse_weight_args` recognizes a fixed set of objective names: accuracy (maximized), tokens/prompt_tokens/completion_tokens/latency (minimized), and any `check:<name>` objective (maximized). Any other name is rejected with this error listing the valid options.","triggerScenarios":"Passing an unsupported objective name in `--weights`, e.g. `--weights cost=1`, `--weights Accuracy=0.5` (case-sensitive match), or a check objective without the `check:` prefix.","commonSituations":"Using a metric name from a different tool; assuming case-insensitivity; referring to a custom test check by its bare name instead of `check:my_check_name`.","solutions":["Use one of the valid names: accuracy, tokens, prompt_tokens, completion_tokens, latency, or check:<name>.","For custom test checks, prefix the check name with `check:`, e.g. `--weights check:groundedness=1.0`.","Match the casing exactly (lowercase for built-in objectives)."],"exampleFix":"// before\nbaml optimize --weights cost=1.0\n// after\nbaml optimize --weights accuracy=0.7,check:relevance=0.3","handlingStrategy":"validation","validationCode":"// Shell: whitelist objectives before invoking\nvalid='^(accuracy|tokens|prompt_tokens|completion_tokens|latency|check:[A-Za-z0-9_-]+)$'\nIFS=',' read -ra parts <<< \"$WEIGHTS\"\nfor p in \"${parts[@]}\"; do\n  name=\"${p%%=*}\"\n  [[ \"$name\" =~ $valid ]] || { echo \"invalid objective: $name\"; exit 1; }\ndone","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Copy objective names exactly from the docs: accuracy, tokens, prompt_tokens, completion_tokens, latency, check:<name>.","Prefix custom test checks with `check:`.","Remember built-in names are lowercase and case-sensitive."],"tags":["cli","invalid-enum-value","objective","optimizer"],"backgroundTag":"invalid-enum-value","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"}