{"record":{"id":"e38720f2725eb669","repo":"we-promise/sure","slug":"too-many-transactions-to-auto-detect-merchants-ma","errorCode":null,"errorMessage":"Too many transactions to auto-detect merchants. Max is 25 per request.","messagePattern":"Too many transactions to auto-detect merchants\\. Max is 25 per request\\.","errorType":"exception","errorClass":"Provider::Anthropic::Error","httpStatus":null,"severity":"error","filePath":"app/models/provider/anthropic.rb","lineNumber":102,"sourceCode":"\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\n      upsert_langfuse_trace(trace: trace, output: result.map(&:to_h))\n\n      result\n    end\n  end\n\n  def auto_detect_merchants(transactions: [], user_merchants: [], model: \"\", family: nil, json_mode: nil)\n    with_provider_response do\n      raise Error, \"Too many transactions to auto-detect merchants. Max is 25 per request.\" if transactions.size > 25\n\n      effective_model = model.presence || @default_model\n\n      trace = create_langfuse_trace(\n        name: \"anthropic.auto_detect_merchants\",\n        input: { transactions: transactions, user_merchants: user_merchants }\n      )\n\n      result = AutoMerchantDetector.new(\n        client,\n        model: effective_model,\n        transactions: transactions,\n        user_merchants: user_merchants,\n        langfuse_trace: trace,\n        family: family\n      ).auto_detect_merchants\n\n      upsert_langfuse_trace(trace: trace, output: result.map(&:to_h))","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/we-promise/sure/blob/e69894adb92547273377398c15f45c979cd9416a/app/models/provider/anthropic.rb#L84-L120","documentation":"Provider::Anthropic#auto_detect_merchants raises Error when transactions.size > 25. Like auto_categorize, the whole list goes into one prompt with a single forced report_merchants tool call, so the provider caps each request at 25 transactions to bound prompt/response size and keep detection quality stable.","triggerScenarios":"Calling auto_detect_merchants(transactions: txns, ...) with 26+ transactions — typically a merchant-detection job over a large import or a scope that lost its batching during a refactor.","commonSituations":"Bulk import followed by a merchant-detection sweep with no slicing; concatenating multiple imports into one call; production data volume exceeding what dev/test exercised.","solutions":["Slice into groups of 25 (each_slice(25) / in_groups_of(25, false)) and call auto_detect_merchants per batch.","Fix the batching in the enqueuing job/service so each enqueued unit is already ≤25 rows.","Reuse the same batching helper used for auto_categorize so both LLM paths share one cap."],"exampleFix":"# before\nprovider.auto_detect_merchants(transactions: pending)\n# => Too many transactions to auto-detect merchants. Max is 25 per request.\n\n# after\npending.each_slice(25) do |batch|\n  provider.auto_detect_merchants(transactions: batch, family: family)\nend","handlingStrategy":"validation","validationCode":"transactions.each_slice(25) do |batch|\n  provider.auto_detect_merchants(transactions: batch, family: family)\nend","typeGuard":null,"tryCatchPattern":"begin\n  provider.auto_detect_merchants(transactions: batch, family: family)\nrescue Provider::Anthropic::Error => e\n  Rails.logger.error(\"merchant detection failed for batch: #{e.message}\")\nend","preventionTips":["Slice scopes with each_slice(25)/find_in_batches(batch_size: 25) before calling LLM features.","Share one batching helper across categorize/detect/enhance so caps never drift.","Boundary-test at 25/26 items."],"tags":["anthropic","llm","batch-limit","merchant-detection","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"}