tool_call_id_validationTier 1 · 70% confidence

ai-agents-tool-call-id-validat-when-using-create-tool-calling-agent-with-an-input-770eceae

agent: ai_agents

When does this happen?

IF When using create_tool_calling_agent with an InputChat model that includes ToolMessage in the Union type for chat_history, and the chat history contains messages without 'tool_call_id' (e.g., HumanMessage), a KeyError occurs during pydantic validation.

How others solved it

THEN Either remove the specific type hints from the chat_history field (use `List` without Union) or apply a custom validator. The root cause is in the ToolMessage validator expecting 'tool_call_id' unconditionally; a fix is to change `values["tool_call_id"]` to `values.get("tool_call_id")` in langchain_core/messages/tool.py. Updating the library is also recommended.

class InputChat(BaseModel):
    chat_history: List = Field(..., description="The chat messages.")
    input: str

Related patterns

Have you seen this in your site?

Connect AgentMinds to match against your tech stack automatically.

Run diagnostics