{"record":{"id":"d5cccba854ee8665","repo":"Unity-Technologies/ml-agents","slug":"sampler-configuration-does-not-contain-sampler-typ","errorCode":null,"errorMessage":"Sampler configuration does not contain sampler_type : {d}.","messagePattern":"Sampler configuration does not contain sampler_type : (.+?)\\.","errorType":"validation","errorClass":"TrainerConfigError","httpStatus":null,"severity":"error","filePath":"ml-agents/mlagents/trainers/settings.py","lineNumber":297,"sourceCode":"        raise TrainerConfigError(f\"__str__ not implemented for type {self.__class__}.\")\n\n    @staticmethod\n    def structure(\n        d: Union[Mapping, float], t: type\n    ) -> \"ParameterRandomizationSettings\":\n        \"\"\"\n        Helper method to a ParameterRandomizationSettings class. Meant to be registered with\n        cattr.register_structure_hook() and called with cattr.structure(). This is needed to handle\n        the special Enum selection of ParameterRandomizationSettings classes.\n        \"\"\"\n        if isinstance(d, (float, int)):\n            return ConstantSettings(value=d)\n        if not isinstance(d, Mapping):\n            raise TrainerConfigError(\n                f\"Unsupported parameter randomization configuration {d}.\"\n            )\n        if \"sampler_type\" not in d:\n            raise TrainerConfigError(\n                f\"Sampler configuration does not contain sampler_type : {d}.\"\n            )\n        if \"sampler_parameters\" not in d:\n            raise TrainerConfigError(\n                f\"Sampler configuration does not contain sampler_parameters : {d}.\"\n            )\n        enum_key = ParameterRandomizationType(d[\"sampler_type\"])\n        t = enum_key.to_settings()\n        return strict_to_cls(d[\"sampler_parameters\"], t)\n\n    @staticmethod\n    def unstructure(d: \"ParameterRandomizationSettings\") -> Mapping:\n        \"\"\"\n        Helper method to a ParameterRandomizationSettings class. Meant to be registered with\n        cattr.register_unstructure_hook() and called with cattr.unstructure().\n        \"\"\"\n        _reversed_mapping = {\n            UniformSettings: ParameterRandomizationType.UNIFORM,","sourceCodeStart":279,"sourceCodeEnd":315,"githubUrl":"https://github.com/Unity-Technologies/ml-agents/blob/3ecb446f75d1e7400eb404c562dc005d3164cffc/ml-agents/mlagents/trainers/settings.py#L279-L315","documentation":"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.","triggerScenarios":"Writing `environment_parameters: {my_param: {sampler_parameters: {min_value: 1, max_value: 2}}}` — the sampler block is a dict but omits `sampler_type`.","commonSituations":"Users add only sampler_parameters (copied from an example) and forget the sampler_type line, or a key typo like `sampler-type`.","solutions":["Add `sampler_type: <uniform|gaussian|multirangeuniform>` to the sampler mapping.","Check for key typos or casing issues (`sampler-type` vs `sampler_type`).","Ensure the sampler_type value is one of the supported enum names."],"exampleFix":"# before\nmy_param:\n  sampler_parameters:\n    min_value: 1.0\n    max_value: 5.0\n\n# after\nmy_param:\n  sampler_type: uniform\n  sampler_parameters:\n    min_value: 1.0\n    max_value: 5.0","handlingStrategy":"validation","validationCode":"for name, spec in cfg.get('environment_parameters', {}).items():\n    if isinstance(spec, dict) and 'sampler_type' not in spec:\n        raise ValueError(f\"environment_parameters[{name}] missing 'sampler_type'\")","typeGuard":"def has_sampler_type(spec) -> bool:\n    return isinstance(spec, dict) and 'sampler_type' in spec","tryCatchPattern":"try:\n    settings = TrainerSettings.structure(raw)\nexcept TrainerConfigError as e:\n    if 'sampler_type' in str(e):\n        print('Add sampler_type: uniform|gaussian|multirangeuniform')\n    raise","preventionTips":["Use a config template that always includes sampler_type","Grep configs for sampler_parameters without a sibling sampler_type","Key typo check: sampler_type uses underscore, not hyphen"],"tags":["config","yaml","parameter-randomization","missing-key"],"backgroundTag":"missing-required-argument","analyzedSha":"3ecb446f75d1e7400eb404c562dc005d3164cffc","analyzedAt":"2026-09-02T16:33:12.832Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}