Jump to solution
Verify

The Fix

pip install pydantic==2.7.2

Based on closed pydantic/pydantic issue #9447 · 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
@@ -593,7 +593,12 @@ def inspect_annotated_serializer(serializer: Callable[..., Any], mode: Literal[' info_arg """ - sig = signature(serializer) + try: + sig = signature(serializer)
repro.py
from typing import Annotated from pydantic import BaseModel, PlainSerializer class Demo(BaseModel): # Commented-out line below works # value: Annotated[str, PlainSerializer(lambda x: str(x))] value: Annotated[str, PlainSerializer(str)]
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 pydantic==2.7.2\nWhen NOT to use: This fix is not applicable if using custom serializers that require different handling.\n\n

Why This Fix Works in Production

  • Trigger: class Demo(BaseModel):
  • Mechanism: The `PlainSerializer` does not accept the built-in object `str` as its `func` argument
  • Why the fix works: Fixes the issue where `PlainSerializer` does not accept the built-in object `str` as its `func` argument. (first fixed release: 2.7.2).
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

  • Shows up under Python 3.12 in real deployments (not just unit tests).
  • The `PlainSerializer` does not accept the built-in object `str` as its `func` argument
  • Surfaces as: Traceback (most recent call last):

Proof / Evidence

Discussion

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

“Now that the commit with the fix has been released, I've tested it out and can confirm the bug is solved. Thank you very much!”
@aphedges · 2024-07-10 · confirmation · source
“Unlike float, str (and a bunch of builtin types) doesn't have a __text_signature__ attribute. I'll look into this issue soon”
@Viicos · 2024-05-17 · source
“@aphedges, Oh no! Thanks for bringing this to our attention. Sorry about that faulty fix! Thanks @Viicos, ping me when you want a review :).”
@sydney-runkle · 2024-05-17 · source

Failure Signature (Search String)

  • class Demo(BaseModel):

Error Message

Stack trace
error.txt
Error Message ------------- Traceback (most recent call last): File "/Users/ahedges/Downloads/test.py", line 6, in <module> class Demo(BaseModel): File "/Users/ahedges/.pyenv/versions/test/lib/python3.12/site-packages/pydantic/_internal/_model_construction.py", line 202, in __new__ complete_model_class( File "/Users/ahedges/.pyenv/versions/test/lib/python3.12/site-packages/pydantic/_internal/_model_construction.py", line 539, in complete_model_class schema = cls.__get_pydantic_core_schema__(cls, handler) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/ahedges/.pyenv/versions/test/lib/python3.12/site-packages/pydantic/main.py", line 626, in __get_pydantic_core_schema__ return handler(source) ^^^^^^^^^^^^^^^ File "/Users/ahedges/.pyenv/versions/test/lib/python3.12/site-packages/pydantic/_internal/_schema_generation_shared.py", line 82, in __call__ schema = self._handler(source_type) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/ahedges/.pyenv/versions/test/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py", line 502, in generate_schema schema = self._generate_schema_inner(obj) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/ahedges/.pyenv/versions/test/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py", line 753, in _generate_schema_inner return self._model_schema(obj) ... (tru ... (truncated) ...

Minimal Reproduction

repro.py
from typing import Annotated from pydantic import BaseModel, PlainSerializer class Demo(BaseModel): # Commented-out line below works # value: Annotated[str, PlainSerializer(lambda x: str(x))] value: Annotated[str, PlainSerializer(str)]

Environment

  • Python: 3.12
  • Pydantic: 2

What Broke

Using `str` with `PlainSerializer` results in a runtime exception.

Why It Broke

The `PlainSerializer` does not accept the built-in object `str` as its `func` argument

Fix Options (Details)

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

pip install pydantic==2.7.2

When NOT to use: This fix is not applicable if using custom serializers that require different handling.

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

Fix reference: https://github.com/pydantic/pydantic/pull/9450

First fixed release: 2.7.2

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

Get updates

We publish verified fixes weekly. No spam.

Subscribe

When NOT to Use This Fix

  • This fix is not applicable if using custom serializers that require different handling.

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

  • Add a CI check that diffs key outputs after upgrades (OpenAPI schema snapshots, JSON payload shapes, CLI output).
  • Upgrade behind a canary and run integration tests against the canary before 100% rollout.

Version Compatibility Table

VersionStatus
2.7.2 Fixed

Related Issues

No related fixes found.

Sources

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