Skip to content

Skip output schema validation for tool error replies - #38

Merged
dbernheisel merged 1 commit into
dbernheisel:mainfrom
merhard:fix/skip-output-validation-on-error
Oct 8, 2026
Merged

dbernheisel merged 1 commit into
dbernheisel:mainfrom
merhard:fix/skip-output-validation-on-error

Conversation

@merhard

@merhard merhard commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Since 0.6.0, every {:reply, result, session} tool reply is validated against the tool's output_schema, including Phantom.Tool.error/1 replies. Error replies have no structuredContent, so validation fails. The client then gets Invalid tool output: $: expected object instead of the tool's error text. For any tool with an output_schema, the model never sees why a call failed.

Repro: declare output_schema: on a tool and return {:reply, Tool.error("reason"), session}. The result is %{isError: true, content: [%{type: :text, text: "Invalid tool output: $: expected object"}]}.

Why skip: in the 2025-11-25 tools spec, a tool execution error is content plus isError: true, with no structuredContent. The official TypeScript SDK skips output validation for errors on both sides. The server returns early if (result.isError). The client validates only when !result.isError ("it MUST return structuredContent (unless it's an error)").

Change: a reply with isError: true skips output validation. Success replies are still validated, and new tests cover both cases.

Tool.error/1 replies carry no structuredContent, so validating them
against output_schema replaced the tool's error text with "Invalid
tool output: $: expected object". The MCP spec's tool execution error
has no structuredContent, and the TypeScript SDK skips output
validation when isError is true.
@dbernheisel
dbernheisel merged commit 4ce57b8 into dbernheisel:main Oct 8, 2026
2 checks passed
@merhard
merhard deleted the fix/skip-output-validation-on-error branch October 8, 2026 20:38
@merhard

merhard commented Oct 8, 2026

Copy link
Copy Markdown
Contributor Author

❤️

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants