def validate(instance, schema, cls=None, *args, **kwargs):  # noqa: D417
    """
    Validate an instance under the given schema.

        >>> validate([2, 3, 4], {"maxItems": 2})
        Traceback (most recent call last):
            ...
        ValidationError: [2, 3, 4] is too long

    :func:`~jsonschema.validators.validate` will first verify that the
    provided schema is itself valid, since not doing so can lead to less
    obvious error messages and fail in less obvious or consistent ways.

    If you know you have a valid schema already, especially
    if you intend to validate multiple instances with
    the same schema, you likely would prefer using the
    `jsonschema.protocols.Validator.validate` method directly on a
    specific validator (e.g. ``Draft202012Validator.validate``).


    Arguments:

        instance:

            The instance to validate

        schema:

            The schema to validate with

        cls (jsonschema.protocols.Validator):

            The class that will be used to validate the instance.

    If the ``cls`` argument is not provided, two things will happen
    in accordance with the specification. First, if the schema has a
    :kw:`$schema` keyword containing a known meta-schema [#]_ then the
    proper validator will be used. The specification recommends that
    all schemas contain :kw:`$schema` properties for this reason. If no
    :kw:`$schema` property is found, the default validator class is the
    latest released draft.

    Any other provided positional and keyword arguments will be passed
    on when instantiating the ``cls``.

    Raises:

        `jsonschema.exceptions.ValidationError`:

            if the instance is invalid

        `jsonschema.exceptions.SchemaError`:

            if the schema itself is invalid

    .. rubric:: Footnotes
    .. [#] known by a validator registered with
        `jsonschema.validators.validates`

    """
    if cls is None:
        cls = validator_for(schema)

    cls.check_schema(schema)
    validator = cls(schema, *args, **kwargs)
    error = exceptions.best_match(validator.iter_errors(instance))
    if error is not None:
        raise error
Validate an instance under the given schema.

>>> validate([2, 3, 4], {"maxItems": 2})
Traceback (most recent call last):
...
ValidationError: [2, 3, 4] is too long

:func:`~jsonschema.validators.validate` will first verify that the
provided schema is itself valid, since not doing so can lead to less
obvious error messages and fail in less obvious or consistent ways.

If you know you have a valid schema already, especially
if you intend to validate multiple instances with
the same schema, you likely would prefer using the
`jsonschema.protocols.Validator.validate` method directly on a
specific validator (e.g. ``Draft202012Validator.validate``).


Arguments:

instance:

The instance to validate

schema:

The schema to validate with

cls (jsonschema.protocols.Validator):

The class that will be used to validate the instance.

If the ``cls`` argument is not provided, two things will happen
in accordance with the specification. First, if the schema has a
:kw:`$schema` keyword containing a known meta-schema [#]_ then the
proper validator will be used. The specification recommends that
all schemas contain :kw:`$schema` properties for this reason. If no
:kw:`$schema` property is found, the default validator class is the
latest released draft.

Any other provided positional and keyword arguments will be passed
on when instantiating the ``cls``.

Raises:

`jsonschema.exceptions.ValidationError`:

if the instance is invalid

`jsonschema.exceptions.SchemaError`:

if the schema itself is invalid

.. rubric:: Footnotes
.. [#] known by a validator registered with
`jsonschema.validators.validates`
jsonschema/validators.py