Initial Checks
Description
When looking at the generated schema for fields allowing the MISSING Sentinel the pattern is lost.
This holds true for assignment of the Field(pattern=...) as well as when using Annotated unless the MISSING sentinel is in the outer union.
This is especially weird as description and title are properly handled in this combination
Example Code
from typing import Annotated
from pydantic import BaseModel, Field
from pydantic.experimental.missing_sentinel import MISSING
def test_missing_schema_pattern_minimal_assignment():
class Model(BaseModel):
a: str | MISSING = Field(title='title', description='Something', pattern='^[a-z]+$')
assert Model.model_json_schema()['properties'] == {
'a': {
'description': 'Something',
'pattern': '^[a-z]+$',
'title': 'title',
'type': 'string',
}
}
def test_missing_schema_pattern_minimal_annotated_in_union():
class Model(BaseModel):
a: Annotated[str, Field(title='title', description='Something', pattern='^[a-z]+$')] | MISSING
assert Model.model_json_schema()['properties'] == {
'a': {
'description': 'Something',
'pattern': '^[a-z]+$',
'title': 'title',
'type': 'string',
}
}
def test_missing_schema_pattern_minimal_annotated_union():
class Model(BaseModel):
a: Annotated[str | MISSING, Field(title='title', description='Something', pattern='^[a-z]+$')]
assert Model.model_json_schema()['properties'] == {
'a': {
'description': 'Something',
'pattern': '^[a-z]+$',
'title': 'title',
'type': 'string',
}
}
Python, Pydantic & OS Version
pydantic version: 2.13.0b2
pydantic-core version: 2.42.0
pydantic-core build: profile=debug pgo=false
python version: 3.13.7 (main, Mar 3 2026, 12:19:54) [GCC 15.2.0]
platform: Linux-6.17.0-19-generic-x86_64-with-glibc2.42
related packages: pyright-1.1.405 pydantic-extra-types-2.10.6 mypy-1.18.2 typing_extensions-4.14.1 pydantic-settings-2.7.1
commit: 704a79d50
Initial Checks
Description
When looking at the generated schema for fields allowing the MISSING Sentinel the pattern is lost.
This holds true for assignment of the
Field(pattern=...)as well as when usingAnnotatedunless theMISSINGsentinel is in the outer union.This is especially weird as
descriptionandtitleare properly handled in this combinationExample Code
Python, Pydantic & OS Version