Skip to content

max_digits and decimal_places do not serialize to json_schema for decimal #10867

@michaelheiser-aiwyn

Description

@michaelheiser-aiwyn

Initial Checks

  • I confirm that I'm using Pydantic V2

Description

Not sure if this is expected or not, but my decimal constraints do not appear to make it to the Jsonschema:

Example Code

from pydantic import TypeAdapter, Field
from typing import Annotated
from decimal import Decimal
constraints = {'max_digits': 5, 'decimal_places': 2, 'ge': 0.0, 'le': 10.0}

TypeAdapter(Annotated[Decimal, Field(**constraints)]).json_schema()
# Out[53]: {'anyOf': [{'maximum': 10.0, 'minimum': 0.0, 'type': 'number'},  {'type': 'string'}]}

Python, Pydantic & OS Version

pydantic version: 2.9.2
        pydantic-core version: 2.23.4
          pydantic-core build: profile=release pgo=false
                 install path: /home/mheiser/src/taxa-backend/.venv/lib/python3.12/site-packages/pydantic
               python version: 3.12.7 (main, Oct  8 2024, 00:20:25) [Clang 18.1.8 ]
                     platform: Linux-5.15.167.4-microsoft-standard-WSL2-x86_64-with-glibc2.35
             related packages: fastapi-0.115.4 typing_extensions-4.12.2 pydantic-settings-2.6.1 pyright-1.1.385
                       commit: unknown

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions