Unity-Technologies/ml-agents · warning · TrainerConfigError

__str__ not implemented for type {self.__class__}.

Error message

__str__ not implemented for type {self.__class__}.

What it means

ParameterRandomizationSettings explicitly overrides `__str__` to raise this TrainerConfigError, so stringifying any parameter-randomization settings object fails. It exists to force callers to output sampler stats through a dedicated mechanism rather than implicit str()/print(). Hitting it means code called str() or f-string formatting on a settings object.

Source

Thrown at ml-agents/mlagents/trainers/settings.py:279

        _mapping = {
            ParameterRandomizationType.UNIFORM: UniformSettings,
            ParameterRandomizationType.GAUSSIAN: GaussianSettings,
            ParameterRandomizationType.MULTIRANGEUNIFORM: MultiRangeUniformSettings,
            ParameterRandomizationType.CONSTANT: ConstantSettings
            # Constant type is handled if a float is provided instead of a config
        }
        return _mapping[self]


@attr.s(auto_attribs=True)
class ParameterRandomizationSettings(abc.ABC):
    seed: int = parser.get_default("seed")

    def __str__(self) -> str:
        """
        Helper method to output sampler stats to console.
        """
        raise TrainerConfigError(f"__str__ not implemented for type {self.__class__}.")

    @staticmethod
    def structure(
        d: Union[Mapping, float], t: type
    ) -> "ParameterRandomizationSettings":
        """
        Helper method to a ParameterRandomizationSettings class. Meant to be registered with
        cattr.register_structure_hook() and called with cattr.structure(). This is needed to handle
        the special Enum selection of ParameterRandomizationSettings classes.
        """
        if isinstance(d, (float, int)):
            return ConstantSettings(value=d)
        if not isinstance(d, Mapping):
            raise TrainerConfigError(
                f"Unsupported parameter randomization configuration {d}."
            )
        if "sampler_type" not in d:
            raise TrainerConfigError(

View on GitHub (pinned to 3ecb446f75)

Solutions

  1. Log individual fields (e.g. `settings.sampler_type`, `settings.sampler_parameters`) instead of the whole object.
  2. Use the library's sampler stats output path (environment parameter channel / stats recorder) for console output.
  3. Remove or guard the debug print that stringifies the settings object.

Example fix

// before
print(f"Randomization settings: {param_settings}")

// after
print(f"Randomization settings: {param_settings.sampler_type} {param_settings.sampler_parameters}")
Defensive patterns

Strategy: try-catch

Validate before calling

if isinstance(obj, ParameterRandomizationSettings):
    logger.info('%s', attr.asdict(obj))
else:
    logger.info('%s', obj)

Type guard

def is_randomization_settings(obj) -> bool:
    return isinstance(obj, ParameterRandomizationSettings)

Try / catch

try:
    desc = str(settings)
except TrainerConfigError:
    desc = repr(attr.asdict(settings))

Prevention

When it happens

Trigger: Calling `str(param_settings)`, printing a ParameterRandomizationSettings instance, or embedding it in an f-string / logging call.

Common situations: Debug logging of the environment parameter randomization config, or generic config dump code that formats every settings object as a string.

Related errors


AI-assisted analysis of Unity-Technologies/ml-agents@3ecb446f75 (2026-09-02). Data as JSON: /api/errors/ea2d30efee9ac419. Report an issue: GitHub.