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.2

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.2
File Size Uploaded Provenance Actions
fastapi_validation_override-1.3.2.tar.gz 377.2 kB Without provenance Details for fastapi_validation_override-1.3.2.tar.gz

Built distribution (wheel)

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

Total release size: 386.8 kB

Release files / fastapi_validation_override-1.3.2.tar.gz

Download URL fastapi_validation_override-1.3.2.tar.gz
Size 377.2 kB
Tags Source
SHA-256 checksum
How to use checksums
9d90dc3f6ea8310cdfc8a6959319f5f175ae75e59d655bb5ff3791bed2272966
BLAKE2b-256 checksum
How to use checksums
f5345fc5efb402a1ad806b8e269dc62f9dbb62d86b20e3502c335f90634abbd8
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.2-py3-none-any.whl

Download URL fastapi_validation_override-1.3.2-py3-none-any.whl
Size 9.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b838be1362c45e150ecf4627482505a573d987595eeec2ad3f2f68b209a7bb3f
BLAKE2b-256 checksum
How to use checksums
8510c2a02501b87f8ca9289ff655389a554c9b5bbe04524ea7fd44b5c0e42079
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.2

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