Skip to content
Back to top
View this page

# Custom error messages

To customize the schema-level error messages that `load` and `loads` use when raising a `ValidationError`, override the `error_messages` class variable:

    class MySchema(Schema):
        error_messages = {
            "unknown": "Custom unknown field error message.",
            "type": "Custom invalid type error message.",
        }

Field-level error message defaults can be set on `Field.default_error_messages`.

    from marshmallow import Schema, fields

    fields.Field.default_error_messages["required"] = "You missed something!"

    class ArtistSchema(Schema):
        name = fields.Str(required=True)
        label = fields.Str(required=True, error_messages={"required": "Label missing."})

    print(ArtistSchema().validate({}))
    # {'label': ['Label missing.'], 'name': ['You missed something!']}