Unity-Technologies/ml-agents · error · TrainerConfigError
Sampler configuration does not contain sampler_parameters :
Error message
Sampler configuration does not contain sampler_parameters : {d}. What it means
The parameter randomization structure hook requires both `sampler_type` and `sampler_parameters` keys; after validating sampler_type it checks for `sampler_parameters` and raises this error if absent. The sampler_parameters value is then strictly converted into the concrete sampler settings class.
Source
Thrown at ml-agents/mlagents/trainers/settings.py:301
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,
GaussianSettings: ParameterRandomizationType.GAUSSIAN,
MultiRangeUniformSettings: ParameterRandomizationType.MULTIRANGEUNIFORM,
ConstantSettings: ParameterRandomizationType.CONSTANT,
}View on GitHub (pinned to 3ecb446f75)
Solutions
- Add a `sampler_parameters` mapping with the required fields (e.g. min_value, max_value for uniform).
- Verify indentation so sampler_parameters nests under the parameter name.
- Compare against a working example config from the ML-Agents repo.
Example fix
# before
my_param:
sampler_type: uniform
# 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_parameters' not in spec:
raise ValueError(f"environment_parameters[{name}] missing 'sampler_parameters'") Type guard
def has_sampler_parameters(spec) -> bool:
return isinstance(spec, dict) and isinstance(spec.get('sampler_parameters'), dict) Try / catch
try:
settings = TrainerSettings.structure(raw)
except TrainerConfigError as e:
if 'sampler_parameters' in str(e):
print('Add sampler_parameters with min_value/max_value etc.')
raise Prevention
- Always pair sampler_type with sampler_parameters in the same mapping
- Validate nested keys with a schema before training runs
- Keep a canonical example config per sampler type
When it happens
Trigger: Writing `environment_parameters: {my_param: {sampler_type: uniform}}` without the sibling `sampler_parameters` mapping.
Common situations: Copying only the sampler_type line from docs, or deleting sampler_parameters when editing values, leaving an incomplete sampler block.
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
- Sampler configuration does not contain sampler_type : {d}.
- Unsupported parameter randomization configuration {d}.
- There was an error decoding Config file from {config_path}.
- Error parsing yaml file. Please check for formatting errors.
- Unsupported reward signal configuration {d}.
AI-assisted analysis of Unity-Technologies/ml-agents@3ecb446f75 (2026-09-02).
Data as JSON: /api/errors/07c12f7911da3709.
Report an issue: GitHub.