Skip to content

AI Agent (V1): a schema-invalid tool call from the model terminates the whole execution instead of being returned as a recoverable error #37916

Description

@HanumanTFM

Bug Description

A model-generated tool call that fails the tool's Zod schema validation terminates the entire AI Agent execution. The end user receives nothing.

With @n8n/n8n-nodes-langchain.agent typeVersion 1.9 (AgentV1), when the model emits a tool_use block whose input does not satisfy the tool's generated schema, the node raises:

NodeOperationError: Received tool input did not match expected schema
✖ Required
  → at query

The workflow ends with status error, lastNodeExecuted: AI Agent, and no output. A single malformed tool call from the model destroys the whole run, including all work already completed in earlier iterations of the same execution.

This is reachable through ordinary configuration and ordinary model behaviour. Anthropic tool use is non-strict by default, which means a JSON Schema required list guides generation but does not constrain it — the model may emit input: {}. We measured this directly at the provider boundary with a transparent proxy between n8n and api.anthropic.com: 33 of 267 tool_use blocks (12.4%) had a completely empty input: {}, on tools that declared required parameters. So the invalid input originates with the model, not with n8n, and n8n's handling of it is what turns a recoverable event into total loss.

There is a perverse consequence: an honest schema is the one that breaks production. Declaring a tool parameter required makes runs fail; supplying a default to $fromAI makes the parameter optional in the emitted schema and the agent survives. Users are pushed toward less accurate tool schemas to keep the agent alive.

To Reproduce

  1. Build an AI Agent (typeVersion 1.9) with an Anthropic Chat Model and at least one sub-workflow tool.
  2. Give the tool one parameter via $fromAI with no default, e.g. {{ $fromAI('query', 'One focused search query', 'string') }}. This produces a schema with required: ["query"]. (Supplying a 4th argument instead adds .default(...), which makes the parameter optional and hides the bug.)
  3. Run a workload where the model issues many tool calls — ours was 25 questions, each producing several.
  4. Whenever the model emits a tool call with no arguments, the execution dies with the error above.

Measured over the same 25-question set, changing only whether the parameter carries a default:

configuration answers delivered failed executions
parameter optional (default supplied) 25 / 25 0
parameter required (no default) 22 / 25 3

All three failures were Received tool input did not match expected schema.

Expected behavior

An invalid tool input should be returned to the model as a recoverable error observation, and the agent loop should continue, rather than terminating the execution.

Concretely: surface the validation failure as a tool result marked as an error, so the model can correct itself and retry on the next iteration. Anthropic explicitly supports continuing the conversation this way — returning a tool_result with is_error: true, after which the model can attempt a corrected call.

This matters beyond one provider. The same path is reachable from any model that emits a schema-invalid tool call, from tools whose schemas cannot use constrained generation, and from application-level validation stricter than JSON Schema.

We observed that AgentV3 appears to route failed AI-tool executions back through the execution engine as error results. If V1 is intentionally frozen and V3 is the supported path for this behaviour, saying so in the docs would fully resolve this report — we are not asking for a V1 backport.

Related: #37915 (same report, auto-closed as a feature request; it is a defect with data loss, so re-filing on the bug template) and #37914 (strict: true passthrough, which would prevent the invalid calls at source for Anthropic but does not address the fatal handling).

Debug Info

Assembled from the deployment and the n8n API rather than Help → About, as this instance is accessed programmatically:

n8n:                       2.37.7 (self-hosted, official image)
agent node:                @n8n/n8n-nodes-langchain.agent  typeVersion 1.9  (AgentV1)
model node:                @n8n/n8n-nodes-langchain.lmChatAnthropic  typeVersion 1.6
@langchain/anthropic:      1.5.6  (per the 2.37.7 workspace catalog)
model:                     claude-opus-5, adaptive thinking, streaming, prompt caching 5m
tools:                     4 client tools, all sub-workflow backed (toolWorkflow)
failing execution status:  error   lastNodeExecuted: AI Agent   no output produced

Operating System

Linux (official n8n Docker image, hosted on Render)

n8n Version

2.37.7

Node.js Version

24.x (official image for the 2.37.7 tag; engines.node >= 24.0.0)

Database

PostgreSQL

Execution mode

main (default)

Hosting

self hosted

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    status:in-linearIssue or PR is now in Linearstatus:team-assignedA team has been assigned the issue or PRteam:aiIssue is with the AI team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions