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

Too many transactions to auto-categorize. Max is 25 per requ

Error message

Too many transactions to auto-categorize. Max is 25 per request.

What it means

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.

Source

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

  def provider_name
    custom_endpoint? ? "Custom Anthropic-compatible (#{@base_url})" : "Anthropic"
  end

  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,

View on GitHub (pinned to e69894adb9)

Solutions

  1. Slice the list into batches of 25 (in_groups_of(25, false) or each_slice(25)) and call auto_categorize per batch.
  2. Find the caller that passes the oversized array (job/service layer) and fix the batching there, not at the raise site.
  3. 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.

Example fix

# before
provider.auto_categorize(transactions: family.transactions.uncategorized.to_a)
# => Too many transactions to auto-categorize. Max is 25 per request.

# after
family.transactions.uncategorized.find_in_batches(batch_size: 25) do |batch|
  provider.auto_categorize(transactions: batch, user_categories: categories, family: family)
end
Defensive patterns

Strategy: validation

Validate before calling

MAX_BATCH = 25
raise ArgumentError, "max #{MAX_BATCH} transactions" if transactions.size > MAX_BATCH
transactions.each_slice(MAX_BATCH) { |b| provider.auto_categorize(transactions: b, user_categories: cats, family: family) }

Try / catch

begin
  provider.auto_categorize(transactions: batch, user_categories: cats, family: family)
rescue Provider::Anthropic::Error => e
  Rails.logger.error("auto_categorize failed: #{e.message}")
end

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


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