# pydantic.errors.UnionError: Unable to validate input for union

- **ID:** `python/pydantic-union-type-validation`
- **Domain:** python
- **Category:** type_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

When a field is typed as Union[A, B], Pydantic tries each type in order; if none match, it raises UnionError, often due to ambiguous types or strict validation.

## Version Compatibility

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

## Workarounds

1. **** (90% success)
   ```
   Use discriminated unions with Literal types: Field(discriminator='type')
   ```
2. **** (85% success)
   ```
   Define a custom validator to handle complex union logic
   ```

## Dead Ends

- **** — Order matters; if first type accepts too broadly, it may consume valid inputs for second type. (70% fail)
- **** — Optional[Union] can still fail if input is None but not allowed. (60% fail)
