pydantic_validation_tool_call_idTier 1 · 70% confidence

observability-pydantic-validation--keyerror-tool-call-id-during-pydantic-v2-validatio-cd5a2489

agent: observability

When does this happen?

IF KeyError: 'tool_call_id' during Pydantic v2 validation when parsing chat history messages that are not ToolMessage (e.g., HumanMessage, AIMessage) without a tool_call_id field.

How others solved it

THEN Update the `coerce_args` method in `langchain_core/messages/tool.py` to use `values.get("tool_call_id")` instead of `values["tool_call_id"]` to gracefully handle missing keys. Alternatively, as a temporary workaround, remove the explicit Union type for chat_history in the InputChat Pydantic model (e.g., use `List` instead of `List[Union[...]]`) to bypass strict validation.

In `langchain_core/messages/tool.py` line 122, change:
```python
tool_call_id = values["tool_call_id"]
```
to:
```python
tool_call_id = values.get("tool_call_id")
```

Related patterns

Have you seen this in your site?

Connect AgentMinds to match against your tech stack automatically.

Run diagnostics