mlflow/mlflow · error · ValueError
validator_name must be provided
Error message
validator_name must be provided
What it means
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.
Source
Thrown at mlflow/genai/scorers/guardrails/__init__.py:74
Args:
validator_name: Name of the Guardrails AI validator
**validator_kwargs: Additional arguments passed to the validator
"""
_guard: Any = PrivateAttr()
def __init__(
self,
validator_name: str | None = None,
**validator_kwargs: Any,
):
check_guardrails_installed()
# Get validator name from class variable if not provided
if validator_name is None:
validator_name = getattr(self.__class__, "validator_name", None)
if validator_name is None:
raise ValueError("validator_name must be provided")
super().__init__(name=validator_name)
from guardrails import Guard, OnFailAction
validator_class = get_validator_class(validator_name)
validator = validator_class(on_fail=OnFailAction.NOOP, **validator_kwargs)
try:
self._guard = Guard().use(validator)
except TypeError:
# guardrails-ai < 0.9.0: on_fail is passed to Guard.use() instead
self._guard = Guard().use(
validator_class, on_fail=OnFailAction.NOOP, **validator_kwargs
)
def __call__(
self,
*,View on GitHub (pinned to 6a27f2decc)
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
Example fix
// before
class MyScorer(GuardrailsScorer):
pass
// after
class MyScorer(GuardrailsScorer):
validator_name = "RegexCheck" Defensive patterns
Strategy: validation
Validate before calling
if validator_name is None and not hasattr(cls, "validator_name"):
raise ValueError("Subclass must define validator_name or pass it to __init__") Type guard
def is_named_validator(cls) -> bool:
return getattr(cls, "validator_name", None) is not None Try / catch
try:
scorer = MyGuardrailsScorer()
except ValueError as e:
if "validator_name must be provided" in str(e):
scorer = MyGuardrailsScorer(validator_name="RegexCheck")
else:
raise Prevention
- 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
When it happens
Trigger: Subclassing the Guardrails scorer base without passing `validator_name` to `__init__` and without declaring `validator_name` as a class attribute; passing an explicit None.
Common situations: 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.
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
- INVALID_PARAMETER_VALUE
- The gateway configuration is invalid: {e}
- Invalid gateway configuration: {e}
- Async scorer '__call__' methods are not supported. Scorer cl
- Failed to create InstructionsJudge scorer '{serialized.name}
AI-assisted analysis of mlflow/mlflow@6a27f2decc (2026-08-29).
Data as JSON: /api/errors/32b32e3b635ce34b.
Report an issue: GitHub.