{"record":{"id":"c22b376270548c98","repo":"we-promise/sure","slug":"too-many-transactions-to-auto-categorize-max-is-2","errorCode":null,"errorMessage":"Too many transactions to auto-categorize. Max is 25 per request.","messagePattern":"Too many transactions to auto-categorize\\. Max is 25 per request\\.","errorType":"exception","errorClass":"Provider::Anthropic::Error","httpStatus":null,"severity":"error","filePath":"app/models/provider/anthropic.rb","lineNumber":71,"sourceCode":"  def provider_name\n    custom_endpoint? ? \"Custom Anthropic-compatible (#{@base_url})\" : \"Anthropic\"\n  end\n\n  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,","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/we-promise/sure/blob/e69894adb92547273377398c15f45c979cd9416a/app/models/provider/anthropic.rb#L53-L89","documentation":"Provider::Anthropic#auto_categorize raises Error when transactions.size > 25. The whole batch is serialized into a single prompt plus one forced tool call (report_categorizations), so the provider enforces a hard cap of 25 transactions per request to keep prompts and responses within model context/output limits and to preserve answer quality.","triggerScenarios":"Calling auto_categorize(transactions: txns, ...) with a list of 26+ transactions — typically an auto-categorization job running over a bulk CSV/import that forgot to slice the scope, or chaining two imports before categorization runs.","commonSituations":"Bulk-import flow (CSV/Sync) enqueues hundreds of uncategorized transactions and the job passes the scope straight through; pagination removed during a refactor; tests using oversized fixture batches pass while production fails.","solutions":["Slice the list into batches of 25 (in_groups_of(25, false) or each_slice(25)) and call auto_categorize per batch.","Find the caller that passes the oversized array (job/service layer) and fix the batching there, not at the raise site.","If you control the provider fork and truly need bigger batches, raise the cap deliberately — but expect degraded accuracy and truncated tool output at high counts."],"exampleFix":"# before\nprovider.auto_categorize(transactions: family.transactions.uncategorized.to_a)\n# => Too many transactions to auto-categorize. Max is 25 per request.\n\n# after\nfamily.transactions.uncategorized.find_in_batches(batch_size: 25) do |batch|\n  provider.auto_categorize(transactions: batch, user_categories: categories, family: family)\nend","handlingStrategy":"validation","validationCode":"MAX_BATCH = 25\nraise ArgumentError, \"max #{MAX_BATCH} transactions\" if transactions.size > MAX_BATCH\ntransactions.each_slice(MAX_BATCH) { |b| provider.auto_categorize(transactions: b, user_categories: cats, family: family) }","typeGuard":null,"tryCatchPattern":"begin\n  provider.auto_categorize(transactions: batch, user_categories: cats, family: family)\nrescue Provider::Anthropic::Error => e\n  Rails.logger.error(\"auto_categorize failed: #{e.message}\")\nend","preventionTips":["Centralize the 25-item cap in one constant/helper shared by all LLM batch entry points.","Enqueue categorization jobs pre-sliced (each job ≤25 rows) instead of slicing inside the provider call.","Add tests at exactly 25 and 26 items to lock the boundary."],"tags":["anthropic","llm","batch-limit","auto-categorization","input-validation"],"backgroundTag":"batch-size-limit-exceeded","analyzedSha":"e69894adb92547273377398c15f45c979cd9416a","analyzedAt":"2026-08-21T18:22:41.165Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}