Skip to content

pydantic.validate_call

Decorators for validating function calls.

validate_call

validate_call(
    __func=None, *, config=None, validate_return=False
)

Returns a decorated version of the function that validates the arguments and, optionally, the return value.

Parameters:

Name Type Description Default
__func AnyCallableT | None

The function to be decorated.

None
config ConfigDict | None

The configuration dictionary.

None
validate_return bool

Whether to validate the return value.

False

Returns:

Type Description
AnyCallableT | Callable[[AnyCallableT], AnyCallableT]

The decorated function.

Source code in pydantic/validate_call.py
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
def validate_call(
    __func: AnyCallableT | None = None,
    *,
    config: ConfigDict | None = None,
    validate_return: bool = False,
) -> AnyCallableT | Callable[[AnyCallableT], AnyCallableT]:
    """Returns a decorated version of the function that validates the arguments and, optionally, the return value.

    Args:
        __func: The function to be decorated.
        config: The configuration dictionary.
        validate_return: Whether to validate the return value.

    Returns:
        The decorated function.
    """

    def validate(function: AnyCallableT) -> AnyCallableT:
        return _validate_call.ValidateCallWrapper(function, config, validate_return)  # type: ignore

    if __func:
        return validate(__func)
    else:
        return validate