The Fix
pip install pydantic==2.11.8
Based on closed pydantic/pydantic issue #11843 · PR/commit linked
@@ -501,3 +501,49 @@ args, kwargs = val.validate_json('{"args": ["arg1"], "kwargs": {"extra": 1}}')
#> ('arg1',) {'extra': 1}
```
+
+## `MISSING` sentinel
+
from typing import Any
from pydantic import GetCoreSchemaHandler, GetJsonSchemaHandler
from pydantic.json_schema import SkipJsonSchema
from pydantic_core import core_schema
class _MissingSentinel:
"""Use this to have different behaviour between
Source: https://github.com/pydantic/pydantic/discussions/9943#discussioncomment-10131374
"""
_instance = None
def __new__(cls):
if not cls._instance:
cls._instance = super().__new__(cls)
return cls._instance
def __repr__(self):
return "<MISSING>"
@classmethod
def __get_pydantic_core_schema__(cls, source_type: Any, _: GetCoreSchemaHandler) -> core_schema.CoreSchema:
return core_schema.is_instance_schema(
cls=source_type,
# Feature request:
# serialization=core_schema.exclude_ser_schema(),
serialization=core_schema.to_string_ser_schema(),
)
@classmethod
def __get_pydantic_json_schema__(cls, core_schema: core_schema.CoreSchema, handler: GetJsonSchemaHandler):
return {}
# Feature Request:
# MissingSentinel = SkipJsonSchema[ExcludeSerialization[_MissingSentinel]]
MissingSentinel = SkipJsonSchema[_MissingSentinel]
MISSING = _MissingSentinel()
class MyModel(BaseModel):
nullable_field: str | None | MissingSentinel = MISSING
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.11.8\nWhen NOT to use: This fix should not be used if the model requires explicit tracking of unset fields.\n\n
Why This Fix Works in Production
- Trigger: I have a 'missing' sentinel value. When the field is set to this sentinel I want it to be excluded from the model serialization.
- Mechanism: The absence of a mechanism to exclude sentinel values from serialization in Pydantic models
- Why the fix works: Introduces an experimental `MISSING` sentinel to exclude fields from serialization in Pydantic models. (first fixed release: 2.11.8).
Why This Breaks in Prod
- The absence of a mechanism to exclude sentinel values from serialization in Pydantic models
- Production symptom (often without a traceback): I have a 'missing' sentinel value. When the field is set to this sentinel I want it to be excluded from the model serialization.
Proof / Evidence
- GitHub issue: #11843
- Fix PR: https://github.com/pydantic/pydantic/pull/11883
- First fixed release: 2.11.8
- 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.40
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“A new MISSING sentinel was introduced in https://github.com/pydantic/pydantic/pull/11883 as an experimental feature, and available to be tested in the 2.12.0a1 release”
Failure Signature (Search String)
- I have a 'missing' sentinel value. When the field is set to this sentinel I want it to be excluded from the model serialization.
- I'd propose adding a `core_schema.exclude_ser_schema()` and an `ExcludeSerialization` annotation.
Copy-friendly signature
Failure Signature
-----------------
I have a 'missing' sentinel value. When the field is set to this sentinel I want it to be excluded from the model serialization.
I'd propose adding a `core_schema.exclude_ser_schema()` and an `ExcludeSerialization` annotation.
Error Message
Signature-only (no traceback captured)
Error Message
-------------
I have a 'missing' sentinel value. When the field is set to this sentinel I want it to be excluded from the model serialization.
I'd propose adding a `core_schema.exclude_ser_schema()` and an `ExcludeSerialization` annotation.
Minimal Reproduction
from typing import Any
from pydantic import GetCoreSchemaHandler, GetJsonSchemaHandler
from pydantic.json_schema import SkipJsonSchema
from pydantic_core import core_schema
class _MissingSentinel:
"""Use this to have different behaviour between
Source: https://github.com/pydantic/pydantic/discussions/9943#discussioncomment-10131374
"""
_instance = None
def __new__(cls):
if not cls._instance:
cls._instance = super().__new__(cls)
return cls._instance
def __repr__(self):
return "<MISSING>"
@classmethod
def __get_pydantic_core_schema__(cls, source_type: Any, _: GetCoreSchemaHandler) -> core_schema.CoreSchema:
return core_schema.is_instance_schema(
cls=source_type,
# Feature request:
# serialization=core_schema.exclude_ser_schema(),
serialization=core_schema.to_string_ser_schema(),
)
@classmethod
def __get_pydantic_json_schema__(cls, core_schema: core_schema.CoreSchema, handler: GetJsonSchemaHandler):
return {}
# Feature Request:
# MissingSentinel = SkipJsonSchema[ExcludeSerialization[_MissingSentinel]]
MissingSentinel = SkipJsonSchema[_MissingSentinel]
MISSING = _MissingSentinel()
class MyModel(BaseModel):
nullable_field: str | None | MissingSentinel = MISSING
What Broke
Models with sentinel values included unwanted fields during serialization, leading to incorrect outputs.
Why It Broke
The absence of a mechanism to exclude sentinel values from serialization in Pydantic models
Fix Options (Details)
Option A — Upgrade to fixed release Safe default (recommended)
pip install pydantic==2.11.8
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/11883
First fixed release: 2.11.8
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- This fix should not be used if the model requires explicit tracking of unset fields.
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.11.8 | Fixed |
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.