we-promise/sure · error · Provider::Anthropic::Error

No categories available for auto-categorization

Error message

No categories available for auto-categorization

What it means

auto_categorize raises Error when user_categories is blank: the categorizer needs the family's category list to map model output onto real category names, so categorization is impossible without it. The provider also logs 'Cannot auto-categorize transactions for family <id>: no categories available' (id falls back to "unknown" when family is nil) before raising.

Source

Thrown at app/models/provider/anthropic.rb:75

  def supported_models_description
    if custom_endpoint?
      "configured model: #{@default_model}"
    else
      "models starting with: #{DEFAULT_ANTHROPIC_MODEL_PREFIXES.join(', ')}"
    end
  end

  def custom_endpoint?
    @base_url.present?
  end

  def auto_categorize(transactions: [], user_categories: [], model: "", family: nil, json_mode: nil)
    with_provider_response do
      raise Error, "Too many transactions to auto-categorize. Max is 25 per request." if transactions.size > 25
      if user_categories.blank?
        family_id = family&.id || "unknown"
        Rails.logger.error("Cannot auto-categorize transactions for family #{family_id}: no categories available")
        raise Error, "No categories available for auto-categorization"
      end

      effective_model = model.presence || @default_model

      trace = create_langfuse_trace(
        name: "anthropic.auto_categorize",
        input: { transactions: transactions, user_categories: user_categories }
      )

      result = AutoCategorizer.new(
        client,
        model: effective_model,
        transactions: transactions,
        user_categories: user_categories,
        langfuse_trace: trace,
        family: family
      ).auto_categorize

View on GitHub (pinned to e69894adb9)

Solutions

  1. Ensure the family has categories before invoking (seed/default the category set for new families, or block deletion of the last category in the UI).
  2. Fix the caller to pass family.categories (a non-empty list) and a non-nil family so the error log shows a real family id.
  3. Add a pre-check in the job: skip categorization with an informational log when the family has no categories instead of raising into the job's failure path.

Example fix

# before
provider.auto_categorize(transactions: txns, user_categories: family.categories.reload.map(&:name), family: nil)
# => No categories available for auto-categorization

# after
categories = family.categories.map(&:name)
if categories.blank?
  Rails.logger.info("Skipping auto-categorize for family #{family.id}: no categories")
else
  provider.auto_categorize(transactions: txns, user_categories: categories, family: family)
end
Defensive patterns

Strategy: validation

Validate before calling

return if transactions.blank?
categories = family.categories.map(&:name)
if categories.blank?
  Rails.logger.info("skip: family #{family.id} has no categories")
  return
end
provider.auto_categorize(transactions: transactions, user_categories: categories, family: family)

Try / catch

begin
  provider.auto_categorize(transactions: txns, user_categories: cats, family: family)
rescue Provider::Anthropic::Error => e
  Rails.logger.error("categorization skipped for family #{family&.id}: #{e.message}")
end

Prevention

When it happens

Trigger: Calling auto_categorize with user_categories: [] or nil — e.g. a family whose categories were all deleted or never created, passing family: nil so the caller-side lookup returned nothing, or a fresh account where default categories have not been seeded yet.

Common situations: New signup before default-category seeding ran/finished; user deleted every category; refactored caller stopped loading family.categories; family argument dropped when the method signature changed.

Understand the failure class

Background: Missing required parameter errors: what 'X is required' and 'the required X param is missing' mean, and how to fix them — this error's family across 27 libraries.

Related errors


AI-assisted analysis of we-promise/sure@e69894adb9 (2026-08-21). Data as JSON: /api/errors/74c328faced6564f. Report an issue: GitHub.