apache/beam · error · ValueError

Unknown algorithm for input_spec

Error message

Unknown algorithm for input_spec: %s. Supported algorithms are "builtin" and "lcg".

What it means

SyntheticSource supports two random-element generation algorithms: the 'builtin' generator and 'lcg' (linear congruential generator). If input_spec['algorithm'] is set to any other string, __init__ raises ValueError listing the supported values. None (key absent) selects the default builtin generator.

Solutions

  1. Set input_spec['algorithm'] to exactly 'builtin' or 'lcg' (lowercase).
  2. Remove the 'algorithm' key to use the default generator.
  3. Validate the algorithm name against ('builtin', 'lcg') before launching the pipeline.

Example fix

// before
input_spec = {'algorithm': 'Lcg'}
// after
input_spec = {'algorithm': 'lcg'}
Defensive patterns

Strategy: validation

Validate before calling

algo = input_spec.get('algorithm')
if algo not in (None, 'builtin', 'lcg'):
    raise ValueError(f'unsupported algorithm: {algo!r}')

Type guard

def is_supported_algorithm(spec: dict) -> bool:
    return spec.get('algorithm') in (None, 'builtin', 'lcg')

Try / catch

try:
    source = SyntheticStep(input_spec, ...)
except ValueError as e:
    if 'Unknown algorithm' in str(e):
        input_spec.pop('algorithm', None)
        source = SyntheticStep(input_spec, ...)
    else:
        raise

Prevention

When it happens

Trigger: Passing input_spec = {'algorithm': 'mersenne'} or {'algorithm': 'BUILTIN'} (case-sensitive) or any value other than None/'builtin'/'lcg' when constructing the source.

Common situations: Typos ('lgc', 'Lcg'); copying algorithm names from other synthetic data tools; assuming case-insensitivity; switching between apache_beam versions where the option exists only in newer releases.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/e9de61f73c488515. Report an issue: GitHub.

Appendix: source

Thrown at sdks/python/apache_beam/testing/synthetic_pipeline.py:402

        raise ValueError(
            'SyntheticSource currently only supports delay '
            'distributions of type \'const\'. Received %s.',
            input_spec['delayDistribution']['type'])
      self._sleep_per_input_record_sec = (
          float(input_spec['delayDistribution']['const']) / 1000)
      if (self._sleep_per_input_record_sec and
          self._sleep_per_input_record_sec < 1e-3):
        raise ValueError(
            'Sleep time per input record must be at least 1e-3.'
            ' Received: %r',
            self._sleep_per_input_record_sec)
    else:
      self._sleep_per_input_record_sec = 0

    # algorithm of the generator
    self.gen_algo = input_spec.get('algorithm', None)
    if self.gen_algo not in (None, 'builtin', 'lcg'):
      raise ValueError(
          'Unknown algorithm for input_spec: %s. Supported '
          'algorithms are "builtin" and "lcg".',
          self.gen_algo)

  @property
  def element_size(self):
    return self._key_size + self._value_size

  def estimate_size(self):
    return self._total_size

  def split(self, desired_bundle_size, start_position=0, stop_position=None):
    # Performs initial splitting of SyntheticSource.
    #
    # Exact sizes and distribution of initial splits generated here depends on
    # the input specification of the SyntheticSource.

    if stop_position is None:

View on GitHub (pinned to 12126d8942)