{"record":{"id":"bb916ab86370402b","repo":"apache/beam","slug":"max-batch-size-exceeded-batch-size-needs-to-be-smaller-than","errorCode":null,"errorMessage":"Max batch_size exceeded. Batch size needs to be smaller than {}","messagePattern":"Max batch_size exceeded\\. Batch size needs to be smaller than (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/ml/gcp/visionml.py","lineNumber":130,"sourceCode":"\n          context_side_input =\n            (\n              p\n              | \"Image contexts\" >> beam.Create(image_contexts)\n            )\n\n          visionml.AnnotateImage(features,\n            context_side_input=beam.pvalue.AsDict(context_side_input)))\n      metadata: (Optional[Sequence[Tuple[str, str]]]): Optional.\n        Additional metadata that is provided to the method.\n    \"\"\"\n    super().__init__()\n    self.features = features\n    self.retry = retry\n    self.timeout = timeout\n    self.max_batch_size = max_batch_size or AnnotateImage.MAX_BATCH_SIZE\n    if self.max_batch_size > AnnotateImage.MAX_BATCH_SIZE:\n      raise ValueError(\n          'Max batch_size exceeded. '\n          'Batch size needs to be smaller than {}'.format(\n              AnnotateImage.MAX_BATCH_SIZE))\n    self.min_batch_size = min_batch_size or AnnotateImage.MIN_BATCH_SIZE\n    self.client_options = client_options\n    self.context_side_input = context_side_input\n    self.metadata = metadata\n\n  def expand(self, pvalue):\n    return (\n        pvalue\n        | FlatMap(self._create_image_annotation_pairs, self.context_side_input)\n        | util.BatchElements(\n            min_batch_size=self.min_batch_size,\n            max_batch_size=self.max_batch_size)\n        | ParDo(\n            _ImageAnnotateFn(\n                features=self.features,","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/ml/gcp/visionml.py#L112-L148","documentation":"AnnotateImage.__init__ validates max_batch_size against AnnotateImage.MAX_BATCH_SIZE (the Cloud Vision API limit on features per AnnotateImageRequest); a larger requested batch cannot be sent as a single request and is rejected up front.","triggerScenarios":"Thrown at sdks/python/apache_beam/ml/gcp/visionml.py:130 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass max_batch_size <= AnnotateImage.MAX_BATCH_SIZE (or omit it to use the default)","If you need more throughput, scale horizontally (more workers) rather than raising batch size"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}