Unity-Technologies/ml-agents · error · TrainerConfigError

Sampler configuration does not contain sampler_type : {d}.

Error message

Sampler configuration does not contain sampler_type : {d}.

What it means

Within the parameter randomization structure hook, once the config is confirmed to be a Mapping it must include a `sampler_type` key that selects which sampler settings class to build. A mapping without `sampler_type` cannot be dispatched and raises this error.

Source

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

        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(
                f"Sampler configuration does not contain sampler_type : {d}."
            )
        if "sampler_parameters" not in d:
            raise TrainerConfigError(
                f"Sampler configuration does not contain sampler_parameters : {d}."
            )
        enum_key = ParameterRandomizationType(d["sampler_type"])
        t = enum_key.to_settings()
        return strict_to_cls(d["sampler_parameters"], t)

    @staticmethod
    def unstructure(d: "ParameterRandomizationSettings") -> Mapping:
        """
        Helper method to a ParameterRandomizationSettings class. Meant to be registered with
        cattr.register_unstructure_hook() and called with cattr.unstructure().
        """
        _reversed_mapping = {
            UniformSettings: ParameterRandomizationType.UNIFORM,

View on GitHub (pinned to 3ecb446f75)

Solutions

  1. Add `sampler_type: <uniform|gaussian|multirangeuniform>` to the sampler mapping.
  2. Check for key typos or casing issues (`sampler-type` vs `sampler_type`).
  3. Ensure the sampler_type value is one of the supported enum names.

Example fix

# before
my_param:
  sampler_parameters:
    min_value: 1.0
    max_value: 5.0

# after
my_param:
  sampler_type: uniform
  sampler_parameters:
    min_value: 1.0
    max_value: 5.0
Defensive patterns

Strategy: validation

Validate before calling

for name, spec in cfg.get('environment_parameters', {}).items():
    if isinstance(spec, dict) and 'sampler_type' not in spec:
        raise ValueError(f"environment_parameters[{name}] missing 'sampler_type'")

Type guard

def has_sampler_type(spec) -> bool:
    return isinstance(spec, dict) and 'sampler_type' in spec

Try / catch

try:
    settings = TrainerSettings.structure(raw)
except TrainerConfigError as e:
    if 'sampler_type' in str(e):
        print('Add sampler_type: uniform|gaussian|multirangeuniform')
    raise

Prevention

When it happens

Trigger: Writing `environment_parameters: {my_param: {sampler_parameters: {min_value: 1, max_value: 2}}}` — the sampler block is a dict but omits `sampler_type`.

Common situations: Users add only sampler_parameters (copied from an example) and forget the sampler_type line, or a key typo like `sampler-type`.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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