Agent with structured response format loops on a failing SQL tool until the recursion limit
A tool-calling agent built with create_agent and a response_format kept calling its SQL tool after the tool returned errors, then stopped with the recursion-limit error instead of terminating on its own. The project could not confirm that the loop is caused by the framework.
- Framework / agent
- LangGraph / LangChain · tool-calling ReAct-style agent (text-to-SQL)
- Remediation attempts
- SUGGESTEDSUGGESTED
- Recurrence
- not documented
- Source languages
- en
- Updated
- 2026-09-30
Sources
- GITHUB ISSUE LangGraph [1.0.6] Bug - Agent infinite looping until recursion limit error is hit — github.com/langchain-ai/langgraph, retrieved 2026-09-29
- GITHUB PULL REQUEST fix: add missing edge from generate_structured_response to END — github.com/langchain-ai/langgraph, retrieved 2026-09-29
Public sample: the full evidence record is free.
Symptoms
- The agent repeatedly calls the same SQL tool after it returns an error REPORTED CLAIM
- The run ends with a recursion-limit error without reaching a stop condition REPORTED CLAIM
Error messages (verbatim)
Recursion limit of 20 reached without hitting a stop condition
Context and trigger
- Agent type
- tool-calling ReAct-style agent (text-to-SQL)
- Component
- prebuilt agent loop (create_agent with response_format)
- Framework
- LangGraph / LangChain (langgraph 1.0.6)
- Model
- not stated
- Task
- text-to-SQL question answering
- Tools
- SQL query tool, metadata catalog tool
- A tool keeps returning an error (here a SQL namespace error) and the agent retries it REPORTED CLAIM
- response_format is set on the agent REPORTED CLAIM
Open questions
- Whether the loop is caused by the framework or by the agent's tools/prompt was not established by the maintainers.
- The proposed missing-edge fix targets create_react_agent; the report uses create_agent.
Root cause UNKNOWN
Not established by the sources.
no verified evidence about the cause
Remediation attempts (2)
Maintainer recommendation: cap tool calls with the built-in tool-call-limit middleware (or custom middleware) instead of relying on the recursion limit.
Status basis: proposed; no evidence it was applied. Verification: not verified.
You can use tool call limit: https://docs.langchain.com/oss/python/langchain/middleware/built-in#tool-call-limit
Proposed code change: add an explicit edge from the generate_structured_response node to END so the graph terminates after the structured response. Not merged.
Status basis: proposed; no evidence it was applied. Verification: not verified.
Change: https://github.com/langchain-ai/langgraph/pull/6733 · not merged
Excerpt of the change (libs/prebuilt/langgraph/prebuilt/chat_agent_executor.py, MIT):
@@ -898,6 +898,8 @@ def should_continue(state: StateSchema) -> str | list[Send]:
agenerate_structured_response,
),
)
+ # After generating structured response, the graph should end
+ workflow.add_edge("generate_structured_response", END)
if post_model_hook is not None:
post_model_hook_paths.append("generate_structured_response")
else:the `generate_structured_response` node is added to the graph but no outgoing edge to `END` is defined. This causes the graph to not terminate properly after generating the structured responseOutcome outcome: UNKNOWN
no applied remediation documented
Recurrence
Not documented in the sources (absence of reports is not evidence of absence).
Confidence LOW
Cause or remediation is reported, but not confirmed by the affected project.
| Factor | Present | Meaning |
|---|---|---|
| first_party_evidence | yes | a quote from the affected project/vendor (or a controlled test) |
| fix_applied | no | a fix was merged/released |
| regression_test | no | tests changed with the fix |
| independent_confirmation | no | reporter/maintainer/vendor confirmed the failure is gone |
| root_cause_verified | no | cause stated by the project and addressed by the fix |
| reproduction_documented | no | steps or conditions to reproduce were quoted |
| multiple_independent_sources | no | 1 independent source group(s) |
| failed_attempts_documented | no | unsuccessful remediation recorded |
All evidence (6 verified quotes)
Agent processing error: Recursion limit of 20 reached without hitting a stop condition. You can increase the limit by setting the `recursion_limit` config key.Databricks SQL query error: [REQUIRES_SINGLE_PART_NAMESPACE] spark_catalog requires a single-part namespace, but got `atlas_data`.`retail`. SQLSTATE: 42K05
response_format=DatabricksQueryGenerationResponse, ).with_config(recursion_limit=self.settings.agent_recursion_limit)
You can use tool call limit: https://docs.langchain.com/oss/python/langchain/middleware/built-in#tool-call-limit
the `generate_structured_response` node is added to the graph but no outgoing edge to `END` is defined. This causes the graph to not terminate properly after generating the structured responseit's unclear which part of it if any is due to langgraphCategories: RETRY LOOP TOOL FAILURECOST FAILURE · extraction curated, gate-2026-09-29-v1
Similarity to your system is not implied. A remediation that worked in the documented context may not work in yours.