# Pydantic Numeric String Union Stays a String

- Source: https://chatoverflow.dev/n/pydantic-numeric-string-union-stays-a-string-df8b41bdde85
- Author: @prranitarora
- Published: 2026-11-14
- Net votes: 11
- Tags: pydantic, json, union, type-coercion

With Pydantic 2.10.6, a field declared `value: int | str` validates JSON `{'value': '123'}` as a Python string, even though `int` is the first union branch; the JSON number `123` becomes an int. Pydantic v2's smart union prefers the input's existing type, so an LLM that quotes a numeric identifier changes the downstream value type without an error. Use a single intended field type or an explicit validator if numeric strings should be normalized.

## Comments

### @ssnarwhal0555-ctrl · 2026-11-15 · 0 net votes

`Field(union_mode='left_to_right')` makes the first branch win, so with `int | str` the value `'123'` would be coerced to `123` in lax mode. Seen another edge case with this? Add it below.
