langchain - 💡(How to fix) Fix `create_agent` should support bounded forced retry after tool invocation validation errors

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Error Message

Deep Agents issue langchain-ai/deepagents#947 reports a failure mode where a model emits a malformed client-side tool call, ToolNode correctly converts the resulting Pydantic validation failure into an error ToolMessage, but the next model turn is allowed to answer in plain text instead of being forced to retry the corrected tool call. 3. The default tool error handler converts that into a ToolMessage(status="error") with text like Please fix the error and try again.

  • Preserve or expose structured information that a prior tool error was a ToolInvocationError wrapping a Pydantic validation failure, rather than requiring consumers to parse ToolMessage.content.
  • langchain-ai/langgraph#7138 proposes surfacing model output metadata in tool error messages. That may help some self-correction cases, but this issue is about runtime/agent-loop enforcement after a known retryable validation error.

Root Cause

  1. The model emits a tool call with invalid args.
  2. ToolNode._execute_tool_sync / _execute_tool_async catches ValidationError and wraps it in ToolInvocationError.
  3. The default tool error handler converts that into a ToolMessage(status="error") with text like Please fix the error and try again.
  4. The agent loop sends that observation back to the model.
  5. The model may respond with plain text containing corrected JSON rather than making the corrected tool call.
  6. Because the response has no tool calls, it is treated as the final answer and leaks incorrect implementation details to the user.
RAW_BUFFERClick to expand / collapse

Privileged issue

  • I am a LangChain maintainer, or was asked directly by a LangChain maintainer to create an issue here.

Issue Content

Deep Agents issue langchain-ai/deepagents#947 reports a failure mode where a model emits a malformed client-side tool call, ToolNode correctly converts the resulting Pydantic validation failure into an error ToolMessage, but the next model turn is allowed to answer in plain text instead of being forced to retry the corrected tool call.

Example failures from the downstream report:

  • task called without required subagent_type
  • filesystem tools called with path instead of schema field file_path

Current flow:

  1. The model emits a tool call with invalid args.
  2. ToolNode._execute_tool_sync / _execute_tool_async catches ValidationError and wraps it in ToolInvocationError.
  3. The default tool error handler converts that into a ToolMessage(status="error") with text like Please fix the error and try again.
  4. The agent loop sends that observation back to the model.
  5. The model may respond with plain text containing corrected JSON rather than making the corrected tool call.
  6. Because the response has no tool calls, it is treated as the final answer and leaks incorrect implementation details to the user.

This is not about failing to detect validation errors — ToolInvocationError already provides the right retryable signal. The missing behavior is an agent-loop policy for retryable tool invocation/schema failures.

Potential design:

  • Preserve or expose structured information that a prior tool error was a ToolInvocationError wrapping a Pydantic validation failure, rather than requiring consumers to parse ToolMessage.content.
  • Add an opt-in or default bounded retry path in create_agent that, after a retryable tool invocation validation failure, forces the next model call to use the same tool via ModelRequest.tool_choice / bind_tools(..., tool_choice=...).
  • Track a retry budget to avoid loops.
  • Scope this to schema/invocation validation failures, not arbitrary runtime tool failures where a natural-language response may be appropriate.
  • Account for provider differences in forcing a specific tool.

Related but not blocking:

  • langchain-ai/langgraph#7138 proposes surfacing model output metadata in tool error messages. That may help some self-correction cases, but this issue is about runtime/agent-loop enforcement after a known retryable validation error.
  • langchain-ai/deepagents#947 is the downstream report that motivated this.

Package (Required)

  • langchain
  • langchain-openai
  • langchain-anthropic
  • langchain-classic
  • langchain-core
  • langchain-model-profiles
  • langchain-tests
  • langchain-text-splitters
  • langchain-chroma
  • langchain-deepseek
  • langchain-exa
  • langchain-fireworks
  • langchain-groq
  • langchain-huggingface
  • langchain-mistralai
  • langchain-nomic
  • langchain-ollama
  • langchain-openrouter
  • langchain-perplexity
  • langchain-qdrant
  • langchain-xai
  • Other / not sure / general

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING