Jump to solution
Verify

The Fix

pip install fastapi==0.128.4

Based on closed fastapi/fastapi issue #13440 · PR/commit linked

Production note: Most teams hit this during upgrades or environment changes. Roll out with a canary and smoke critical endpoints (health, OpenAPI/docs) before 100%.

Jump to Verify Open PR/Commit
@@ -406,6 +406,68 @@ To exclude a query parameter from the generated OpenAPI schema (and thus, from t {* ../../docs_src/query_params_str_validations/tutorial014_an_py310.py hl[10] *} +## Custom Validation + +There could be cases where you need to do some **custom validation** that can't be done with the parameters shown above.
repro.py
from typing import Annotated from pydantic import AfterValidator from fastapi import FastAPI app = FastAPI() def validator(v): raise ValueError() Ints = Annotated[list[int], AfterValidator(validator)] @app.post("/") def post(ints: Ints) -> None: return None
verify
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
fix.md
Option A — Upgrade to fixed release\npip install fastapi==0.128.4\nWhen NOT to use: Do not use this fix if you require the previous behavior of returning 200 for invalid inputs.\n\n

Why This Fix Works in Production

  • Trigger: Validations in `Annotated` like `AfterValidator` do not work in FastAPI 0.115.10
  • Mechanism: Adds documentation examples and tests for custom validations using `Annotated` with `AfterValidator`, reverting a previous change that caused issues with validation in FastAPI 0.115.10.
  • Why the fix works: Adds documentation examples and tests for custom validations using `Annotated` with `AfterValidator`, reverting a previous change that caused issues with validation in FastAPI 0.115.10. (first fixed release: 0.128.4).
Production impact:
  • If left unfixed, the same config can fail only in production (env differences), causing startup failures or partial feature outages.

Why This Breaks in Prod

  • Production symptom (often without a traceback): Validations in `Annotated` like `AfterValidator` do not work in FastAPI 0.115.10

Proof / Evidence

Discussion

High-signal excerpts from the issue thread (symptoms, repros, edge-cases).

“This was handled in https://github.com/fastapi/fastapi/pull/13442 That reverted the PR that introduced the problem, and added docs for these specific use cases, including source examples and…”
@tiangolo · 2025-03-01 · confirmation · source

Failure Signature (Search String)

  • Validations in `Annotated` like `AfterValidator` do not work in FastAPI 0.115.10
  • raise ValueError()
Copy-friendly signature
signature.txt
Failure Signature ----------------- Validations in `Annotated` like `AfterValidator` do not work in FastAPI 0.115.10 raise ValueError()

Error Message

Signature-only (no traceback captured)
error.txt
Error Message ------------- Validations in `Annotated` like `AfterValidator` do not work in FastAPI 0.115.10 raise ValueError()

Minimal Reproduction

repro.py
from typing import Annotated from pydantic import AfterValidator from fastapi import FastAPI app = FastAPI() def validator(v): raise ValueError() Ints = Annotated[list[int], AfterValidator(validator)] @app.post("/") def post(ints: Ints) -> None: return None

What Broke

Requests to endpoints using `Annotated` returned 200 instead of 422 for validation errors.

Fix Options (Details)

Option A — Upgrade to fixed release Safe default (recommended)

pip install fastapi==0.128.4

When NOT to use: Do not use this fix if you require the previous behavior of returning 200 for invalid inputs.

Use when you can deploy the upstream fix. It is usually lower-risk than long-lived workarounds.

Fix reference: https://github.com/fastapi/fastapi/pull/13442

First fixed release: 0.128.4

Last verified: 2026-02-08. Validate in your environment.

Get updates

We publish verified fixes weekly. No spam.

Subscribe

When NOT to Use This Fix

  • Do not use this fix if you require the previous behavior of returning 200 for invalid inputs.

Verify Fix

verify
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.

Did This Fix Work in Your Case?

Quick signal helps us prioritize which fixes to verify and improve.

Prevention

  • Capture the exact failing error string in logs and tests so you can reproduce via a minimal script.
  • Pin production dependencies and upgrade only with a reproducible test that hits the failing path.

Version Compatibility Table

VersionStatus
0.128.4 Fixed

Related Issues

No related fixes found.

Sources

We don’t republish the full GitHub discussion text. Use the links above for context.