{"id":"f7a53fa0bc92b2c2","repo":"pydantic/pydantic","slug":"validator-with-no-fields-specified","errorCode":null,"errorMessage":"validator with no fields specified","messagePattern":"validator with no fields specified","errorType":"exception","errorClass":"ConfigError","httpStatus":null,"severity":"error","filePath":"pydantic/v1/class_validators.py","lineNumber":72,"sourceCode":"    pre: bool = False,\n    each_item: bool = False,\n    always: bool = False,\n    check_fields: bool = True,\n    whole: Optional[bool] = None,\n    allow_reuse: bool = False,\n) -> Callable[[AnyCallable], 'AnyClassMethod']:\n    \"\"\"\n    Decorate methods on the class indicating that they should be used to validate fields\n    :param fields: which field(s) the method should be called on\n    :param pre: whether or not this validator should be called before the standard validators (else after)\n    :param each_item: for complex objects (sets, lists etc.) whether to validate individual elements rather than the\n      whole object\n    :param always: whether this method and other validators should be called even if the value is missing\n    :param check_fields: whether to check that the fields actually exist on the model\n    :param allow_reuse: whether to track and raise an error if another validator refers to the decorated function\n    \"\"\"\n    if not fields:\n        raise ConfigError('validator with no fields specified')\n    elif isinstance(fields[0], FunctionType):\n        raise ConfigError(\n            \"validators should be used with fields and keyword arguments, not bare. \"  # noqa: Q000\n            \"E.g. usage should be `@validator('<field_name>', ...)`\"\n        )\n    elif not all(isinstance(field, str) for field in fields):\n        raise ConfigError(\n            \"validator fields should be passed as separate string args. \"  # noqa: Q000\n            \"E.g. usage should be `@validator('<field_name_1>', '<field_name_2>', ...)`\"\n        )\n\n    if whole is not None:\n        warnings.warn(\n            'The \"whole\" keyword argument is deprecated, use \"each_item\" (inverse meaning, default False) instead',\n            DeprecationWarning,\n        )\n        assert each_item is False, '\"each_item\" and \"whole\" conflict, remove \"whole\"'\n        each_item = not whole","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/pydantic/pydantic/blob/2e5f0e2b4218de31709f1cf9c5bc61ea97a68835/pydantic/v1/class_validators.py#L54-L90","documentation":"Raised by pydantic v1's @validator decorator when it is invoked with zero positional field arguments (e.g. @validator() or @validator(pre=True)). The decorator requires at least one target field name so it knows which model attribute to run the validator against; with no fields there is nothing to bind it to. pydantic raises this at decoration time (class creation) rather than at validation time so the mistake is caught early.","triggerScenarios":"Calling `validator()` with only keyword args: `@validator(pre=True)` over a method; or calling `@validator()` with empty parens; or programmatically `validator(pre=True)(some_fn)`. The guard at class_validators.py:71 `if not fields:` fires before any field binding.","commonSituations":"Copy-pasting a validator and deleting the field-name string but leaving the parentheses; migrating code where a generic 'apply to all' intent was expected (use '*' for that); IDE autocomplete inserting `@validator()` as a stub.","solutions":["Pass at least one field name as a positional string, e.g. `@validator('name')`.","To target every field, use the wildcard: `@validator('*')`.","To target multiple fields, list them separately: `@validator('email', 'phone')`."],"exampleFix":"# before\n@validator(pre=True)\ndef normalize(cls, v):\n    return v\n\n# after\n@validator('name', pre=True)\ndef normalize(cls, v):\n    return v","handlingStrategy":"validation","validationCode":"from pydantic.v1.class_validators import validator\n\ndef safe_validator(*fields, **kwargs):\n    if not fields:\n        raise ValueError('At least one field name is required')\n    return validator(*fields, **kwargs)","typeGuard":"def has_field_arg(*fields) -> bool:\n    return len(fields) > 0 and all(isinstance(f, str) for f in fields)","tryCatchPattern":"try:\n    @validator('field')\n    def v(cls, value): ...\nexcept Exception as e:\n    raise RuntimeError(f'Validator misconfigured: {e}') from e","preventionTips":["Always pass at least one quoted field name to @validator.","Use '*' explicitly when you intend all fields.","Lint for bare @validator() calls in CI."],"tags":["pydantic","validator","decorator","config-error"],"analyzedSha":"2e5f0e2b4218de31709f1cf9c5bc61ea97a68835","analyzedAt":"2026-08-04T19:54:21.281Z","schemaVersion":2}