I had the need of displaying a more detailed custom message to the user when an error occurred. I did this by adding a field to the property in the schema and then looking it up on ValidationError.

import json
import jsonschema


def validate(_data, _schema):
    try:
        jsonschema.validate(_data, _schema)
    except jsonschema.ValidationError as e:
        return e.schema.get("error_msg", e.message)


schema = {
    "title": "index",
    "type": "object",
    "required": [
        "author",
        "description"
    ],
    "properties": {
        "author": {
            "type": "string",
            "description": "Name of the Author",
            "minLength": 3,
            "default": "",
            "error_msg": "Please provide a Author name"
        },
        "description": {
            "type": "string",
            "description": "Short description",
            "minLength": 10,
            "default": "",
            "error_msg": "Please add a short description"
        }
    }
}

data = {
    "author": "Jerakin",
    "description": ""
}
Answer from Jerakin on Stack Overflow
🌐
jsonschema
python-jsonschema.readthedocs.io › en › stable › validate
Schema Validation - jsonschema 4.26.0 documentation
If you aren’t already comfortable with writing schemas and need an introduction which teaches about JSON Schema the specification, you may find Understanding JSON Schema to be a good read! The simplest way to validate an instance under a given schema is to use the validate function. ...
🌐
jsonschema
python-jsonschema.readthedocs.io › en › latest › validate
Schema Validation - jsonschema 4.26.1.dev25+gad0a1b301 documentation
If you aren’t already comfortable with writing schemas and need an introduction which teaches about JSON Schema the specification, you may find Understanding JSON Schema to be a good read! The simplest way to validate an instance under a given schema is to use the validate function. ...
🌐
jsonschema
python-jsonschema.readthedocs.io › en › stable › creating
Creating or Extending Validator Classes - jsonschema 4.26.0 documentation
If you wish to change or extend the meta schema in the new validator class, modify META_SCHEMA directly on the returned class. Note that no implicit copying is done, so a copy should likely be made before modifying it, in order to not affect the old validator. jsonschema.validators.validator_for(schema, default: type[Validator] | _utils.Unset = <unset>) → type[Validator][source]
🌐
PyPI
pypi.org › project › jsonschema
jsonschema · PyPI
An implementation of JSON Schema validation for Python
      » pip install jsonschema
    
Published   Jan 07, 2026
Version   4.26.0
🌐
jsonschema
python-jsonschema.readthedocs.io › en › latest › creating
Creating or Extending Validator Classes - jsonschema 4.25.2.dev84+gcb2d77980 documentation
If you wish to change or extend the meta schema in the new validator class, modify META_SCHEMA directly on the returned class. Note that no implicit copying is done, so a copy should likely be made before modifying it, in order to not affect the old validator. jsonschema.validators.validator_for(schema, default: type[Validator] | _utils.Unset = <unset>) → type[Validator][source]
🌐
Rad's blog
lat.sk › home › jsonchema: custom type, format and validator in python
jsonchema: Custom type, format and validator in Python » Rad's blog
February 24, 2024 - def is_positive(validator, value, instance, schema): if not isinstance(instance, Number): yield ValidationError("%r is not a number" % instance) def is_positive(validator, value, instance, schema): if not isinstance(instance, Number): yield ValidationError("%r is not a number" % instance) if value and instance &lt;= 0: yield ValidationError("%r is not positive integer" % (instance,)) elif not value and instance > 0: yield ValidationError("%r is not negative integer nor zero" % (instance,)) A vali­da­tor must yield a Vali­dati­o­nError when the vali­dati­on fails. You can get inspi­red in jsonschema._validators.
🌐
Stackademic
blog.stackademic.com › elevating-data-integrity-with-advanced-json-schema-custom-validators-in-python-7a3d4b134445
Elevating Data Integrity with Advanced JSON Schema Custom Validators in Python | by Utkarsh Singh | Stackademic
February 16, 2024 - Use the Custom Validator in Your Schema: Reference your custom validator in your JSON schema using the keyword you registered. Let’s start with a relatively straightforward example — ensuring that business hours specified in a JSON object are logical, with the opening time preceding the ...
Find elsewhere
🌐
jsonschema
python-jsonschema.readthedocs.io › en › latest › api › jsonschema › validators
jsonschema.validators - jsonschema 4.26.1.dev25+gad0a1b301 documentation
Creation and extension of validators, with implementations for existing drafts. class jsonschema.validators.Draft201909Validator(schema: bool | ~collections.abc.Mapping[str, ~typing.Any], resolver=None, format_checker: ~jsonschema._format.FormatChecker | None = None, *, registry: ~referencing._core.Registry[bool | ~collections.abc.Mapping[str, ~typing.Any]] = <Registry (20 resources)>, _resolver=None)¶
🌐
PyPI
pypi.org › project › jsonschema-rs
jsonschema-rs - A high-performance JSON Schema validator ...
Custom keywords are classes that receive the keyword value during schema compilation and validate instances at runtime: import jsonschema_rs class DivisibleBy: def __init__(self, parent_schema, value, schema_path): self.divisor = value def validate(self, instance): if isinstance(instance, int) and instance % self.divisor != 0: raise ValueError(f"{instance} is not divisible by {self.divisor}") validator = jsonschema_rs.validator_for( {"type": "integer", "divisibleBy": 3}, keywords={"divisibleBy": DivisibleBy}, ) validator.is_valid(9) # True validator.is_valid(10) # False
      » pip install jsonschema-rs
    
🌐
Readthedocs
python-jsonschema.readthedocs.io › en › v4.8.0 › validate
Schema Validation - jsonschema 4.8.0 documentation
It is assumed to be valid, and providing an invalid schema can lead to undefined behavior. See Validator.check_schema to validate a schema first. resolver – an instance of jsonschema.RefResolver that will be used to resolve $ref properties (JSON references).
🌐
jsonschema
python-jsonschema.readthedocs.io › en › stable › api › jsonschema › validators
jsonschema.validators - jsonschema 4.26.0 documentation
Creation and extension of validators, with implementations for existing drafts. class jsonschema.validators.Draft201909Validator(schema: bool | ~collections.abc.Mapping[str, ~typing.Any], resolver=None, format_checker: ~jsonschema._format.FormatChecker | None = None, *, registry: ~referencing._core.Registry[bool | ~collections.abc.Mapping[str, ~typing.Any]] = <Registry (20 resources)>, _resolver=None)¶
🌐
Stuarteberg
stuarteberg.github.io › jsonschema › validate.html
Schema Validation — jsonschema 2.5.1.post17 documentation
If no $schema property is found, the default validator class is Draft4Validator. Any other provided positional and keyword arguments will be passed on when instantiating the cls. ... The default mapping of JSON types to Python types used when validating type properties in JSON schemas.
🌐
Read the Docs
app.readthedocs.org › projects › python-jsonschema › downloads › pdf › latest pdf
jsonschema Release 4.26.1.dev25+gad0a1b301 Julian Berman Mar 02, 2026
are suitable for most users - each of the versioned validators that are included with jsonschema have a TypeChecker · that can correctly handle their respective versions. ... For an example of providing a custom type check. ... Chapter 7. Contents ... A type property checker. A TypeChecker performs type checking for a Validator, converting between the defined JSON Schema types ... Modifying the behavior just mentioned by redefining which Python objects are considered to be of which JSON
🌐
Stuarteberg
stuarteberg.github.io › jsonschema › creating.html
Creating or Extending Validator Classes — jsonschema 2.5.1.post17 documentation
Create a new validator class. jsonschema.validators.extend(validator, validators, version=None)[source]¶
🌐
Google Groups
groups.google.com › g › jsonschema › c › nPIQE6Hlr-c
Creating a custom type with a custom validation function
The goal is to be able to first define a custom type definition in my schema, and then register a validation function that's triggered on that type:
🌐
Readthedocs
python-jsonschema.readthedocs.io › en › v4.13.0 › validate
Schema Validation - jsonschema 4.13.0 documentation
It is assumed to be valid, and providing an invalid schema can lead to undefined behavior. See Validator.check_schema to validate a schema first. resolver – an instance of jsonschema.RefResolver that will be used to resolve $ref properties (JSON references).
🌐
CodeRivers
coderivers.org › blog › json-schema-validator-python
JSON Schema Validator in Python: A Comprehensive Guide - CodeRivers
April 24, 2025 - You can create a custom validator by subclassing the jsonschema.Draft7Validator (or the appropriate draft version) and overriding the validation methods.