# OutputParserException: Parsing LLM output produced by 'PydanticOutputParser' failed. Error: 1 validation error for WeatherResponse
temperature
  Input should be a valid number [type=float_type, input_value='72.5°F', input_type=str]

- **ID:** `llm/langchain-output-parser-schema-mismatch`
- **Domain:** llm
- **Category:** data_error
- **Verification:** ai_generated
- **Fix Rate:** 78%

## Root Cause

LLM output contains extra non-numeric characters (e.g., units like '°F') that the Pydantic output parser cannot coerce into the expected numeric type.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| langchain 0.2.0 | active | — | — |
| langchain-openai 0.1.0 | active | — | — |
| pydantic 2.5.0 | active | — | — |
| GPT-4 Turbo | active | — | — |
| Claude 3 Opus | active | — | — |

## Workarounds

1. **Add a post-processing step to strip units before parsing. In code: `raw_output = llm_output.replace('°F', '').replace('°C', ''); parsed = parser.parse(raw_output)`.** (85% success)
   ```
   Add a post-processing step to strip units before parsing. In code: `raw_output = llm_output.replace('°F', '').replace('°C', ''); parsed = parser.parse(raw_output)`.
   ```
2. **Use a custom prompt that explicitly forbids units, e.g., 'Return temperature as a plain number without units like °F or °C.'** (80% success)
   ```
   Use a custom prompt that explicitly forbids units, e.g., 'Return temperature as a plain number without units like °F or °C.'
   ```
3. **Switch to `JsonOutputParser` with a post-validation step using Pydantic, allowing more flexible parsing of numeric fields.** (75% success)
   ```
   Switch to `JsonOutputParser` with a post-validation step using Pydantic, allowing more flexible parsing of numeric fields.
   ```

## Dead Ends

- **** — The issue is not randomness; the LLM is following its training to include units. Temperature 0 still produces units in many cases. (70% fail)
- **** — The output is complete but includes extra text; max_tokens does not affect the content format. (90% fail)
- **** — LangChain's PydanticOutputParser does not use OpenAI's response_format internally; it parses arbitrary text output. The JSON mode may not be compatible with the parser's prompt template. (60% fail)
