# ValidationError: 1 validation error for ResponseModel
name
  Field required [type=missing, input_value={'title': 'Test'}, input_type=dict]

- **ID:** `llm/langchain-output-parser-optional-field-missing`
- **Domain:** llm
- **Category:** data_error
- **Verification:** ai_generated
- **Fix Rate:** 82%

## Root Cause

LLM output in JSON mode omits a required field defined in the Pydantic output parser schema, causing validation failure when the response is parsed.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| langchain 0.1.0 | active | — | — |
| langchain 0.1.5 | active | — | — |
| langchain 0.2.0 | active | — | — |
| pydantic 2.5.0 | active | — | — |
| pydantic 2.6.0 | active | — | — |

## Workarounds

1. **Add explicit field instructions in the system prompt to ensure LLM includes all required fields:

from langchain.output_parsers import PydanticOutputParser
parser = PydanticOutputParser(pydantic_object=ResponseModel)
prompt = PromptTemplate(
    template="Generate JSON output. Ensure the following fields are always present: {format_instructions}\n{query}",
    input_variables=["query"],
    partial_variables={"format_instructions": parser.get_format_instructions()},
)** (90% success)
   ```
   Add explicit field instructions in the system prompt to ensure LLM includes all required fields:

from langchain.output_parsers import PydanticOutputParser
parser = PydanticOutputParser(pydantic_object=ResponseModel)
prompt = PromptTemplate(
    template="Generate JSON output. Ensure the following fields are always present: {format_instructions}\n{query}",
    input_variables=["query"],
    partial_variables={"format_instructions": parser.get_format_instructions()},
)
   ```
2. **Implement a fallback parser that fills missing fields with None or defaults and logs the omission for monitoring:

try:
    parsed = parser.parse(llm_output)
except ValidationError:
    import json
    data = json.loads(llm_output)
    data.setdefault('name', 'unknown')
    parsed = ResponseModel(**data)** (85% success)
   ```
   Implement a fallback parser that fills missing fields with None or defaults and logs the omission for monitoring:

try:
    parsed = parser.parse(llm_output)
except ValidationError:
    import json
    data = json.loads(llm_output)
    data.setdefault('name', 'unknown')
    parsed = ResponseModel(**data)
   ```

## Dead Ends

- **** — Defeats the purpose of schema enforcement; LLM may skip critical fields entirely, leading to downstream data inconsistency. (50% fail)
- **** — LLM behavior is non-deterministic; retrying the same prompt often yields the same omission pattern, especially with temperature=0. (70% fail)
