BoundaryML/baml · error

Unknown objective: ' '. Valid objectives: accuracy, tokens…

Error message

Unknown objective: '{}'. Valid objectives: accuracy, tokens, prompt_tokens, completion_tokens, latency, check:<name>

What it means

`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.

Solutions

  1. Use one of the valid names: accuracy, tokens, prompt_tokens, completion_tokens, latency, or check:<name>.
  2. For custom test checks, prefix the check name with `check:`, e.g. `--weights check:groundedness=1.0`.
  3. Match the casing exactly (lowercase for built-in objectives).

Example fix

// before
baml optimize --weights cost=1.0
// after
baml optimize --weights accuracy=0.7,check:relevance=0.3
Defensive patterns

Strategy: validation

Validate before calling

// Shell: whitelist objectives before invoking
valid='^(accuracy|tokens|prompt_tokens|completion_tokens|latency|check:[A-Za-z0-9_-]+)$'
IFS=',' read -ra parts <<< "$WEIGHTS"
for p in "${parts[@]}"; do
  name="${p%%=*}"
  [[ "$name" =~ $valid ]] || { echo "invalid objective: $name"; exit 1; }
done

Prevention

When it happens

Trigger: 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.

Common situations: 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`.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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

Appendix: source

Thrown at engine/baml-runtime/src/optimize/pareto.rs:414

    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
                ),
            };

            objectives.push(Objective {
                name: name.to_string(),
                weight,
                direction,
            });
        }
    }

    // Ensure accuracy is included
    if !objectives.iter().any(|o| o.name == "accuracy") {
        objectives.insert(
            0,
            Objective {

View on GitHub (pinned to bd85ce9dee)