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

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.0
File Size Uploaded Provenance Actions
fastapi_validation_override-1.3.0.tar.gz 369.3 kB Without provenance Details for fastapi_validation_override-1.3.0.tar.gz

Built distribution (wheel)

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

Total release size: 378.9 kB

Release files / fastapi_validation_override-1.3.0.tar.gz

Download URL fastapi_validation_override-1.3.0.tar.gz
Size 369.3 kB
Tags Source
SHA-256 checksum
How to use checksums
729aa51aa0c1dc9e9850230cae0516b68df267e44dc92aa23d198b2efeef4b85
BLAKE2b-256 checksum
How to use checksums
48dba2e44e10b2f1949a59735b3324fbd1bea2cbfafea8c4401331b4f10059ef
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.0-py3-none-any.whl

Download URL fastapi_validation_override-1.3.0-py3-none-any.whl
Size 9.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
01612abb787b38dfa8171047d0bf8dc184258a62da2d20c0c7235998179e5353
BLAKE2b-256 checksum
How to use checksums
41386ef211aa0bc4324011a9e177f96d6d5051f1eb5e04ff88e5ec103fb7ef88
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.0

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