# OutputParserException: Parsing LLM output produced by 'StructuredOutputParser' failed — value 'large' not in enum ['small', 'medium']

- **ID:** `llm/langchain-output-parser-enum`
- **Domain:** llm
- **Category:** data_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

LLM generated a value outside the specified enum constraints when using LangChain's structured output parsers with Pydantic models, often due to insufficient prompting or model hallucination.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| langchain>=0.1.0 | active | — | — |
| langchain-core>=0.1.0 | active | — | — |
| pydantic>=2.0.0 | active | — | — |

## Workarounds

1. **Improve the prompt to explicitly list allowed enum values and instruct the model to only output those exact values: 'The size must be exactly one of: small, medium. Do not output any other value.'** (85% success)
   ```
   Improve the prompt to explicitly list allowed enum values and instruct the model to only output those exact values: 'The size must be exactly one of: small, medium. Do not output any other value.'
   ```
2. **Use LangChain's with_structured_output method on chat models that support JSON mode, which enforces schema constraints at the API level rather than relying on parsing.** (90% success)
   ```
   Use LangChain's with_structured_output method on chat models that support JSON mode, which enforces schema constraints at the API level rather than relying on parsing.
   ```
3. **Implement a post-processing fallback that maps out-of-enum values to the closest valid enum member using a similarity heuristic or manual mapping.** (75% success)
   ```
   Implement a post-processing fallback that maps out-of-enum values to the closest valid enum member using a similarity heuristic or manual mapping.
   ```

## Dead Ends

- **** — This defeats the purpose of constrained output; the LLM may still generate unexpected values outside the expanded set (70% fail)
- **** — Even with temperature=0, LLMs can produce non-deterministic outputs due to floating-point rounding or model updates (50% fail)
- **** — Silent fallback masks errors and may produce incorrect downstream results, leading to hard-to-debug issues (80% fail)
