AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

Agents Silently Fail To Produce Structured_response When Model Omits Tool Call

Using create_agent with response_format=ToolStrategy and a model returning an AIMessage without tool_calls results in a response missing the structured_response key instead of raising an error (handle_errors=False) or retrying (handle_errors=True), causing silent downstream failures.

highConfidence 92%LangchainEmbeddingsRetrieversChainsAffected V1.2.13

Origin Analysis

The output handling conditional in langchain.agents.factory only processes ToolStrategy when output is an AIMessage and output.tool_calls is truthy. An AIMessage with no tool_calls bypasses all branches and is returned unchanged, skipping structured output validation/error handling.
Define a fake chat model that returns AIMessage(content='NOT a tool call') with no tool_calls. Bind tools and call create_agent(model=model, tools=[fake_tool], response_format=ToolStrategy(Parrot, handle_errors=False)). Invoke with a user message. The try/except does not catch StructuredOutputValidationError, and the response lacks the 'structured_response' key, causing assertion failure.

Fixing Code Block

Edge Case Audit

This change may cause additional retry loops for models that legitimately stop without making a structured output tool call, especially if handle_errors=True and the model repeatedly fails; ensure the agent has a retry limit or use handle_errors=False with explicit outer error handling. The new NoStructuredOutputError will propagate in async/concurrent agents and may require updating tests that currently allow missing structured_response. In LangGraph checkpoints/streaming, the extra ToolMessage may alter message flow. Rollback: remove the added elif and the new class/import; the existing ToolStrategy branch for tool_calls remains unchanged.

Ecosystem Topology

Agent Frameworks

LangChain, LlamaIndex, and Pydantic

  1. highProperty graph relation keys collide when entity IDs or labels contain underscores
  2. highCodeActAgent drops assistant tool-call metadata during handoff, leaving an orphan tool response
  3. high[Bug]: HierarchicalNodeParser async methods return the documents unsplit
  4. highLLM.predict_and_call fails with ValidationError for non-function-calling models when react_chat_formatter is omitted
  5. highAnthropic streaming server-tool input_json_delta overwrites completed client tool_use arguments due to stale cur_tool_call state