alibaba/open-code-review · error

invalid boolean for llm.use_anthropic: %w

Error message

invalid boolean for llm.use_anthropic: %w

What it means

The llm.use_anthropic key accepts only Go strconv.ParseBool-compatible booleans (1, t, T, true, TRUE, 0, f, false...). Any other string fails to parse and the strconv error is wrapped as "invalid boolean for llm.use_anthropic: %w".

Source

Thrown at cmd/opencodereview/config_cmd.go:555

		// the point of setting rather than accepted and ignored at resolve time.
		if normalized == llm.ProtocolAnthropicBedrock {
			return fmt.Errorf("llm.protocol cannot be %q: bedrock derives its host from aws_region and signs with the AWS credential chain, so it has no use for llm.url or llm.auth_token; run `ocr config set provider bedrock` instead", normalized)
		}
		cfg.Llm.Protocol = normalized
		// Mirror use_anthropic so older binaries that predate llm.protocol
		// still pick the right protocol family: anthropic -> true, the OpenAI
		// family (including openai-responses) -> false.
		if normalized == llm.ProtocolAnthropic {
			t := true
			cfg.Llm.UseAnthropic = &t
		} else {
			f := false
			cfg.Llm.UseAnthropic = &f
		}
	case "llm.use_anthropic", "llm.UseAnthropic":
		b, err := strconv.ParseBool(value)
		if err != nil {
			return fmt.Errorf("invalid boolean for llm.use_anthropic: %w", err)
		}
		cfg.Llm.UseAnthropic = &b
		// Mirror protocol for backward compatibility. true always selects
		// anthropic. false only mirrors to the legacy openai default when
		// protocol is unset or already a legacy value (anthropic/openai);
		// openai-responses is preserved to avoid a silent downgrade.
		if b {
			cfg.Llm.Protocol = llm.ProtocolAnthropic
		} else if cfg.Llm.Protocol == "" || cfg.Llm.Protocol == llm.ProtocolAnthropic || cfg.Llm.Protocol == llm.ProtocolOpenAIChatCompletions {
			cfg.Llm.Protocol = llm.ProtocolOpenAIChatCompletions
		}
	case "language", "Language":
		cfg.Language = value
	case "telemetry.enabled", "telemetry.Enabled":
		b, err := strconv.ParseBool(value)
		if err != nil {
			return fmt.Errorf("invalid boolean for telemetry.enabled: %w", err)
		}

View on GitHub (pinned to 5cf97d0d15)

Solutions

  1. Use `true` or `false`: `ocr config set llm.use_anthropic true`
  2. Prefer the modern key: `ocr config set llm.protocol anthropic` (or openai/openai-responses) which also mirrors use_anthropic
  3. Check the shell variable actually expands to true/false (`echo $VAL`)
  4. Note Go accepts "1"/"0" and "t"/"f" too, but not yes/no/on/off

Example fix

// before
ocr config set llm.use_anthropic yes
// after
ocr config set llm.use_anthropic true
Defensive patterns

Strategy: validation

Validate before calling

switch strings.ToLower(v) {
case "true", "1", "t": v = "true"
case "false", "0", "f": v = "false"
default:
    return fmt.Errorf("llm.use_anthropic needs true/false, got %q", v)
}
_ = runConfigSet("llm.use_anthropic", v)

Try / catch

if err := runConfigSet("llm.use_anthropic", v); err != nil {
    if strings.Contains(err.Error(), "invalid boolean for llm.use_anthropic") {
        fmt.Fprintf(os.Stderr, "use true/false (Go ParseBool), not yes/no/on/off\n")
    }
}

Prevention

When it happens

Trigger: `ocr config set llm.use_anthropic yes|on|Yes|1.0|<empty>` — values humans write for booleans that strconv.ParseBool rejects.

Common situations: Writing "yes"/"no" out of habit from YAML; leaving the value empty due to a shell variable that failed to expand; a provisioning script emitting "enabled"/"disabled".

Related errors


AI-assisted analysis of alibaba/open-code-review@5cf97d0d15 (2026-09-02). Data as JSON: /api/errors/19f05a675693c8d8. Report an issue: GitHub.