{"record":{"id":"32b32e3b635ce34b","repo":"mlflow/mlflow","slug":"validator-name-must-be-provided","errorCode":null,"errorMessage":"validator_name must be provided","messagePattern":"validator_name must be provided","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"mlflow/genai/scorers/guardrails/__init__.py","lineNumber":74,"sourceCode":"    Args:\n        validator_name: Name of the Guardrails AI validator\n        **validator_kwargs: Additional arguments passed to the validator\n    \"\"\"\n\n    _guard: Any = PrivateAttr()\n\n    def __init__(\n        self,\n        validator_name: str | None = None,\n        **validator_kwargs: Any,\n    ):\n        check_guardrails_installed()\n\n        # Get validator name from class variable if not provided\n        if validator_name is None:\n            validator_name = getattr(self.__class__, \"validator_name\", None)\n            if validator_name is None:\n                raise ValueError(\"validator_name must be provided\")\n\n        super().__init__(name=validator_name)\n\n        from guardrails import Guard, OnFailAction\n\n        validator_class = get_validator_class(validator_name)\n        validator = validator_class(on_fail=OnFailAction.NOOP, **validator_kwargs)\n        try:\n            self._guard = Guard().use(validator)\n        except TypeError:\n            # guardrails-ai < 0.9.0: on_fail is passed to Guard.use() instead\n            self._guard = Guard().use(\n                validator_class, on_fail=OnFailAction.NOOP, **validator_kwargs\n            )\n\n    def __call__(\n        self,\n        *,","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/mlflow/mlflow/blob/6a27f2decc0b76eb1b54af31849784addb357dbc/mlflow/genai/scorers/guardrails/__init__.py#L56-L92","documentation":"The Guardrails scorer base class resolves the validator name either from the explicit `validator_name` argument or from a `validator_name` class variable on the subclass. If both are absent, `__init__` raises this plain ValueError because it cannot determine which Guardrails validator to instantiate.","triggerScenarios":"Subclassing the Guardrails scorer base without passing `validator_name` to `__init__` and without declaring `validator_name` as a class attribute; passing an explicit None.","commonSituations":"Writing a custom validator subclass and forgetting the class variable; refactoring a subclass away from positional args; copying a subclass skeleton that left validator_name unset.","solutions":["Pass validator_name explicitly to the constructor","Set `validator_name = \"YourValidator\"` as a class attribute on the subclass","Ensure the subclass is actually instantiated (not the abstract base directly) with a name"],"exampleFix":"// before\nclass MyScorer(GuardrailsScorer):\n    pass\n// after\nclass MyScorer(GuardrailsScorer):\n    validator_name = \"RegexCheck\"","handlingStrategy":"validation","validationCode":"if validator_name is None and not hasattr(cls, \"validator_name\"):\n    raise ValueError(\"Subclass must define validator_name or pass it to __init__\")","typeGuard":"def is_named_validator(cls) -> bool:\n    return getattr(cls, \"validator_name\", None) is not None","tryCatchPattern":"try:\n    scorer = MyGuardrailsScorer()\nexcept ValueError as e:\n    if \"validator_name must be provided\" in str(e):\n        scorer = MyGuardrailsScorer(validator_name=\"RegexCheck\")\n    else:\n        raise","preventionTips":["Always declare validator_name as a class attribute in custom subclasses","Pass validator_name explicitly at construction instead of relying on inheritance","Lint custom scorer subclasses for the validator_name attribute"],"tags":["python","mlflow","genai","configuration"],"backgroundTag":"missing-required-argument","analyzedSha":"6a27f2decc0b76eb1b54af31849784addb357dbc","analyzedAt":"2026-08-29T20:54:51.419Z","schemaVersion":2},"datasetVersion":"2026-08-29T22:17:34.462Z"}