mudler/LocalAI · error

router/rerank: at least one policy is required

Error message

router/rerank: at least one policy is required

What it means

Construction-time panic in the routing rerank classifier: NewRerankClassifier was called with an empty policies slice. Policies (label + description pairs) are what get scored against the reranker, so zero policies leaves the classifier with nothing to classify — a programming/config invariant, not a runtime data condition.

Source

Thrown at core/services/routing/router/rerank.go:41

	labels    []string
	documents []string
	cache     *labelSetCache

	// budget trims the query to the reranker model's context minus the
	// longest policy description (paired with the query per rerank call);
	// nil reranks Probe.Prompt as built by the caller.
	budget *lazyBudget
}

// defaultRerankActivationThreshold is the relevance floor a label
// must clear to be considered active. Reranker scores live in [0, 1]
// for cross-encoder / ColBERT heads; 0.5 picks "more positive than
// not on this label."
const defaultRerankActivationThreshold = 0.5

func NewRerankClassifier(policies []ScorePolicy, reranker backend.Reranker, cacheCap int, activationThreshold float64) *RerankClassifier {
	if len(policies) == 0 {
		panic("router/rerank: at least one policy is required")
	}
	if reranker == nil {
		panic("router/rerank: reranker is required (configure router.classifier_model)")
	}
	for _, p := range policies {
		if p.Label == "" {
			panic("router/rerank: policy has empty label")
		}
		if p.Description == "" {
			panic(fmt.Sprintf("router/rerank: policy %q has no description", p.Label))
		}
	}
	if activationThreshold <= 0 {
		activationThreshold = defaultRerankActivationThreshold
	}
	labels := make([]string, len(policies))
	docs := make([]string, len(policies))
	for i, p := range policies {

View on GitHub (pinned to 44413a9d06)

Solutions

  1. Add at least one policy (label + description) to the router's classifier config
  2. Check YAML indentation so policies are nested under the classifier section
  3. If constructing in Go, guard the call site: only build the classifier when len(policies) > 0
  4. Validate config at load time so the error surfaces as a config error rather than a panic

Example fix

# before (yaml)
router:
  classifier:
    type: rerank
    policies: []
# after
router:
  classifier:
    type: rerank
    policies:
      - label: code
        description: "requests about programming"
Defensive patterns

Strategy: validation

Validate before calling

if len(cfg.Router.Classifier.Policies) == 0 {
    return fmt.Errorf("router: classifier requires at least one policy")
}

Type guard

func hasPolicies(p []ScorePolicy) bool { return len(p) > 0 }

Try / catch

// panics are construction-time; recover only at plugin boundaries
defer func() { if r := recover(); r != nil { log.Printf("router init failed: %v", r) } }()

Prevention

When it happens

Trigger: Router config enables a rerank-based classifier but defines no policies under it; programmatically calling NewRerankClassifier(nil, ...) or with an empty slice; a config loader that silently drops malformed policy entries and passes the emptied slice through.

Common situations: YAML router section with classifier enabled but an empty/omitted policies list; indentation mistakes that detach policies from the classifier block; tests constructing the classifier with no policies.

Related errors


AI-assisted analysis of mudler/LocalAI@44413a9d06 (2026-08-15). Data as JSON: /api/errors/a7ec814e49b2434b. Report an issue: GitHub.