Repository navigation
gateway: 400 when a required tool choice leaves nothing callable - #169
Conversation
Added validation to ensure required tool choice is callable.
Added conditions to ensure tool choice is set correctly based on allowed function names and tool availability.
|
Checked through the gateway: Responses Two things before merging:
|
Refactor request parsing to handle required tool choices and improve error handling.
…d ANY allowedFunctionNames Updated the logic for function calling modes to include 'VALIDATED' alongside 'ANY'. Adjusted comments for clarity regarding allowed function declarations.
|
Thanks! Re-reviewed the new head line by line and ran it end to end through the gateway against scripted upstreams — all the cases from my previous review now pass, and the new tests fail without the change. Merged; ships in v0.1.350. (#168 had been closed at the same moment as your update comment, which looked accidental, so I reopened it to merge.) |
Summary
Follow-up to #164, invited by @yetone in #164 (comment). When a required Responses
allowed_toolschoice or a GeminiANYlist selects no declared callable function, translating it without tools can return plain text even though the caller required a tool call.Return a clear 400 for those two filtered cases when no function or allowed web search remains. The check runs in the shared parse boundary, so translated routes and Kiro, Cursor, Devin, and Claude subscription routes use the same rule. Do not reject other required choices: Anthropic server tools, Chat custom tools, and Responses custom/MCP tools may still matter to their callers. Native Responses passthrough is not changed.
Tests
The new cases initially reproduced the silent 200 for filtered Responses and Gemini requests. After review, added failing-on-previous-patch controls for Anthropic server tools, Chat custom tools, and Responses custom/MCP tools, plus the four account/subscription paths that bypass translation. Allowed web search and native Responses passthrough remain covered. The fake search server is not a complete search provider; those cases assert it was contacted rather than rejected before forwarding.
GOPROXY=off GOSUMDB=off go test ./internal/gateway -count=1passed on main 42a1379 with this patch. No live provider or account was used.Instinct assisted with the change and tests.