# pydantic_core._pydantic_core.ValidationError: 1 validation error for User
age
  Input should be a valid integer, unable to parse string as an integer [type=int_parsing, input_value='twenty', input_type=str]

- **ID:** `python/pydantic-validation-error-input-type`
- **Domain:** python
- **Category:** data_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Pydantic v2 strict type coercion: a string field was passed where an int was declared, and the string is not a numeric literal so Pydantic refuses to coerce it. Unlike v1, v2 no longer silently coerces arbitrary strings to ints by default.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 2.x | active | — | — |

## Workarounds

1. **** (85% success)
   ```
   from pydantic import BaseModel, field_validator

class User(BaseModel):
    age: int

    @field_validator('age', mode='before')
    @classmethod
    def parse_age(cls, v):
        if isinstance(v, str) and v.isalpha():
            words = {'twenty': 20, 'thirty': 30}
            return words.get(v.lower(), v)
        return v
   ```
2. **** (80% success)
   ```
   from typing import Union
from pydantic import BaseModel, BeforeValidator
from typing_extensions import Annotated

CoercedInt = Annotated[int, BeforeValidator(lambda v: int(v) if str(v).isdigit() else v)]

class User(BaseModel):
    age: CoercedInt
   ```

## Dead Ends

- **** — Silently swallowing ValidationError means the invalid object never gets constructed; downstream code receives None or crashes with AttributeError later. (90% fail)
- **** — strict=False only relaxes some coercions; 'twenty' is not a valid integer representation and will still raise int_parsing. (75% fail)
- **** — v1 also raises for non-numeric strings like 'twenty'; the behavior difference is only for numeric-looking strings such as '25'. (60% fail)
