Skip to content

fix(gateway): convert execution-denied tool results to text#10665

Closed
nicoalbanese wants to merge 2 commits intomainfrom
na/8cd4a434
Closed

fix(gateway): convert execution-denied tool results to text#10665
nicoalbanese wants to merge 2 commits intomainfrom
na/8cd4a434

Conversation

@nicoalbanese
Copy link
Copy Markdown
Collaborator

@nicoalbanese nicoalbanese commented Nov 27, 2025

Background

When a user denies a tool execution approval (answers "n" to an approval prompt), the SDK creates a tool result with output: { type: 'execution-denied' }. The Gateway API doesn't recognize this type, returning GatewayInvalidRequestError: Invalid input at "prompt",3,"content",0,"output".

Other providers (OpenAI, Anthropic, Mistral, etc.) handle this by converting execution-denied to plain text in their message converters before sending to their APIs.

Summary

  • Renamed maybeEncodeFileParts()preparePrompt() to reflect its broader responsibility
  • Added conversion of execution-denied tool results to { type: 'text', value: reason } before sending to Gateway API
  • Added tests for the conversion

Manual Verification

  1. Run examples/ai-core/src/stream-text/openai-tool-approval.ts
  2. Change provider/model to use gateway
  3. Ask for weather somewhere, then reject the execution approval
  4. Verify no error is thrown and the model responds appropriately

Checklist

  • Tests have been added / updated (for bug fixes / features)
  • Documentation has been added / updated (for bug fixes / features)
  • A patch changeset for relevant packages has been added (for bug fixes / features - run pnpm changeset in the project root)
  • I have reviewed this pull request (self-review)

Related Issues

Fixes #10663

@nicoalbanese nicoalbanese marked this pull request as ready for review November 27, 2025 17:28
@nicoalbanese nicoalbanese marked this pull request as draft December 3, 2025 10:50
@nicoalbanese
Copy link
Copy Markdown
Collaborator Author

DO NOT MERGE

@shaper looking into gateway fix here.
cc @lgrammel

@gr2m gr2m added ai/provider related to a provider package. Must be assigned together with at least one `provider/*` label provider/gateway Issues related to the @ai-sdk/gateway provider and removed ai/gateway labels Mar 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai/provider related to a provider package. Must be assigned together with at least one `provider/*` label provider/gateway Issues related to the @ai-sdk/gateway provider

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: tool execution approval not working with gateway

2 participants