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%.
@@ -593,7 +593,12 @@ def inspect_annotated_serializer(serializer: Callable[..., Any], mode: Literal['
info_arg
"""
- sig = signature(serializer)
+ try:
+ sig = signature(serializer)
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)]
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
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).
- 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
- GitHub issue: #9447
- Fix PR: https://github.com/pydantic/pydantic/pull/9450
- First fixed release: 2.7.2
- Reproduced locally: No (not executed)
- Last verified: 2026-02-09
- Confidence: 0.95
- Did this fix it?: Yes (upstream fix exists)
- Own content ratio: 0.37
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!”
“Unlike float, str (and a bunch of builtin types) doesn't have a __text_signature__ attribute. I'll look into this issue soon”
“@aphedges, Oh no! Thanks for bringing this to our attention. Sorry about that faulty fix! Thanks @Viicos, ping me when you want a review :).”
Failure Signature (Search String)
- class Demo(BaseModel):
Error Message
Stack trace
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
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
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.
When NOT to Use This Fix
- This fix is not applicable if using custom serializers that require different handling.
Verify Fix
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
| Version | Status |
|---|---|
| 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.