{"record":{"id":"74c328faced6564f","repo":"we-promise/sure","slug":"no-categories-available-for-auto-categorization","errorCode":null,"errorMessage":"No categories available for auto-categorization","messagePattern":"No categories available for auto-categorization","errorType":"exception","errorClass":"Provider::Anthropic::Error","httpStatus":null,"severity":"error","filePath":"app/models/provider/anthropic.rb","lineNumber":75,"sourceCode":"  def supported_models_description\n    if custom_endpoint?\n      \"configured model: #{@default_model}\"\n    else\n      \"models starting with: #{DEFAULT_ANTHROPIC_MODEL_PREFIXES.join(', ')}\"\n    end\n  end\n\n  def custom_endpoint?\n    @base_url.present?\n  end\n\n  def auto_categorize(transactions: [], user_categories: [], model: \"\", family: nil, json_mode: nil)\n    with_provider_response do\n      raise Error, \"Too many transactions to auto-categorize. Max is 25 per request.\" if transactions.size > 25\n      if user_categories.blank?\n        family_id = family&.id || \"unknown\"\n        Rails.logger.error(\"Cannot auto-categorize transactions for family #{family_id}: no categories available\")\n        raise Error, \"No categories available for auto-categorization\"\n      end\n\n      effective_model = model.presence || @default_model\n\n      trace = create_langfuse_trace(\n        name: \"anthropic.auto_categorize\",\n        input: { transactions: transactions, user_categories: user_categories }\n      )\n\n      result = AutoCategorizer.new(\n        client,\n        model: effective_model,\n        transactions: transactions,\n        user_categories: user_categories,\n        langfuse_trace: trace,\n        family: family\n      ).auto_categorize\n","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/we-promise/sure/blob/e69894adb92547273377398c15f45c979cd9416a/app/models/provider/anthropic.rb#L57-L93","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["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).","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.","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."],"exampleFix":"# before\nprovider.auto_categorize(transactions: txns, user_categories: family.categories.reload.map(&:name), family: nil)\n# => No categories available for auto-categorization\n\n# after\ncategories = family.categories.map(&:name)\nif categories.blank?\n  Rails.logger.info(\"Skipping auto-categorize for family #{family.id}: no categories\")\nelse\n  provider.auto_categorize(transactions: txns, user_categories: categories, family: family)\nend","handlingStrategy":"validation","validationCode":"return if transactions.blank?\ncategories = family.categories.map(&:name)\nif categories.blank?\n  Rails.logger.info(\"skip: family #{family.id} has no categories\")\n  return\nend\nprovider.auto_categorize(transactions: transactions, user_categories: categories, family: family)","typeGuard":null,"tryCatchPattern":"begin\n  provider.auto_categorize(transactions: txns, user_categories: cats, family: family)\nrescue Provider::Anthropic::Error => e\n  Rails.logger.error(\"categorization skipped for family #{family&.id}: #{e.message}\")\nend","preventionTips":["Seed default categories at family creation so the precondition always holds.","Prevent deleting the last remaining category in the UI.","Skip with an info log when categories are empty instead of letting the job fail."],"tags":["anthropic","llm","auto-categorization","categories","precondition"],"backgroundTag":"missing-required-parameter","analyzedSha":"e69894adb92547273377398c15f45c979cd9416a","analyzedAt":"2026-08-21T18:22:41.165Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}