crowdsecurity/crowdsec · error

invalid prior: must be > 0 and <= 1

Error message

invalid prior: must be > 0 and <= 1

What it means

BayesianType.Validate checks that bayesian_prior is strictly greater than 0 and at most 1, since a prior is a probability. This error means the configured prior falls outside (0, 1] — zero, negative, or greater than 1 — so the Bayesian math would be meaningless and the bucket is rejected.

Source

Thrown at pkg/leakybucket/buckettype.go:113

		return fmt.Errorf("invalid leakspeed '%s': must be > 0", f.Spec.LeakSpeed)
	}

	return nil
}

func (ConditionalType) BuildProcessors(_ *BucketFactory) []Processor {
	return []Processor{&DumbProcessor{}}
}

type BayesianType struct{}

func (BayesianType) Validate(f *BucketFactory) error {
	if len(f.Spec.BayesianConditions) == 0 {
		return errors.New("bayesian conditions are required")
	}

	if f.Spec.BayesianPrior <= 0 || f.Spec.BayesianPrior > 1 {
		return errors.New("invalid prior: must be > 0 and <= 1")
	}

	if f.Spec.BayesianThreshold == 0 || f.Spec.BayesianThreshold > 1 {
		return errors.New("invalid threshold: must be > 0 and <= 1")
	}

	if f.Spec.Capacity != -1 {
		return errors.New("capacity must be -1")
	}

	return nil
}

func (BayesianType) BuildProcessors(_ *BucketFactory) []Processor {
	return []Processor{&DumbProcessor{}}
}

View on GitHub (pinned to 909b515798)

Solutions

  1. Set bayesian_prior to a value in (0, 1], e.g. 0.5 — convert percentages by dividing by 100
  2. Check that the value isn't 0 due to a defaulted/unset field
  3. Confirm it's a plain number in YAML, not quoted or expressed with a unit
  4. Also fix bayesian_threshold if it's 0 or > 1 (the next validation check)
  5. Reload the scenario and verify the bucket loads

Example fix

// before
# bayesian_prior: 50
// after
# bayesian_prior: 0.5
Defensive patterns

Strategy: validation

Validate before calling

// before loading the bucket config
if b.Spec.Type == "bayesian" {
    if b.Spec.BayesianPrior <= 0 || b.Spec.BayesianPrior > 1 {
        return fmt.Errorf("bayesian_prior must be in (0, 1], got %v", b.Spec.BayesianPrior)
    }
}

Try / catch

if err := BayesianType{}.Validate(factory); err != nil {
    if strings.Contains(err.Error(), "invalid prior") {
        return fmt.Errorf("bayesian bucket %q: bayesian_prior is a probability in (0, 1], e.g. 0.5", factory.Name)
    }
    return err
}

Prevention

When it happens

Trigger: Loading a type: bayesian bucket whose `bayesian_prior:` is 0, negative, or > 1 (e.g. written as a percentage like 50 instead of 0.5).

Common situations: Specifying the prior as a percentage (0-100) instead of a fraction; leaving bayesian_prior at 0 because it was unset and defaulted; typo such as 1.5 or -0.2 in the scenario YAML.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of crowdsecurity/crowdsec@909b515798 (2026-09-06). Data as JSON: /api/errors/915863d0aaaec6b0. Report an issue: GitHub.