Skip to main content

FastAPI Validation Override logo

FastAPI Validation Override

Build Status codecov pypi package Supported Python versions License: MIT

FastAPI answers every request that fails validation with 422 Unprocessable Entity, and documents that 422 on every route that validates input. Changing it takes two separate pieces: an exception handler for the response, and a patch of the OpenAPI schema for the docs. override_validation_error does both in one call, so the status code your API returns is the one its docs show.

Documentation: https://fastapi-validation-override.matblack81.com/


What you can change

Parameter Default What it changes
status_code 400 The status code of the validation error, in the response and in the schema
error_builder None The body of the error, built from your own Pydantic model, which the schema documents too
media_type "application/json" The content type of the error, e.g. application/problem+json for RFC 9457 Problem Details
merge_target_response True Whether a response the route already declares at the same code is merged with the validation error
handle_exceptions True Whether the response comes from the built-in handler or from yours

The schema is patched across paths, webhooks and callbacks, on top of any custom app.openapi function you already have.


Requirements

  • Python 3.10+
  • FastAPI 0.120.0+

Installation

pip install fastapi-validation-override
# or
uv add fastapi-validation-override

Quick start

Call override_validation_error with your app:

from fastapi import FastAPI
from pydantic import BaseModel

from fastapi_validation_override import override_validation_error

app = FastAPI()


class Item(BaseModel):
    name: str
    price: float


@app.post("/items")
def create_item(item: Item) -> Item:
    return item


override_validation_error(app)

The response, the schema, the other options and the parameter reference are in the documentation.


Release Notes

RELEASE_NOTES


License

MIT

Metadata

Release files for fastapi-validation-override 1.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fastapi-validation-override 1.3.1
File Size Uploaded Provenance Actions
fastapi_validation_override-1.3.1.tar.gz 377.0 kB Without provenance Details for fastapi_validation_override-1.3.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for fastapi-validation-override 1.3.1
File Interpreter ABI Platform Actions
fastapi_validation_override-1.3.1-py3-none-any.whl Python 3 none any Details for fastapi_validation_override-1.3.1-py3-none-any.whl

Total release size: 386.5 kB

Release files / fastapi_validation_override-1.3.1.tar.gz

Download URL fastapi_validation_override-1.3.1.tar.gz
Size 377.0 kB
Tags Source
SHA-256 checksum
How to use checksums
8297e0aa6859043ce95e97332c3fccaa11752dbd82e73c55e98ed151b7712c58
BLAKE2b-256 checksum
How to use checksums
f087c6d291ce5a0fe16c21c09297f642ea7b2534e481fd77695f97b0c870b6d7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.18 {"installer":{"name":"uv","version":"0.11.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / fastapi_validation_override-1.3.1-py3-none-any.whl

Download URL fastapi_validation_override-1.3.1-py3-none-any.whl
Size 9.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ec5b5f2465c07966a633b49a623caed88498807e19c64cbfe0177f7c552bb189
BLAKE2b-256 checksum
How to use checksums
fccdb2ea7957d916c41308bfce8f449158d0b871771a8f81326e56f99e203d20
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.18 {"installer":{"name":"uv","version":"0.11.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for fastapi-validation-override 1.3.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page