fix(ai-gateway): improve tool call error reporting#2815
Open
kilo-code-bot[bot] wants to merge 2 commits intomainfrom
Open
fix(ai-gateway): improve tool call error reporting#2815kilo-code-bot[bot] wants to merge 2 commits intomainfrom
kilo-code-bot[bot] wants to merge 2 commits intomainfrom
Conversation
Use z.treeifyError for schema_mismatch details instead of the already-JSON-stringified result.error.message, and model details as a discriminated union on kind so schema errors are stored as structured data rather than an opaque string.
Contributor
Author
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Files Reviewed (1 files)
Reviewed by gpt-5.4-20260305 · 208,400 tokens |
…ools When the model emits a tool call whose name isn't in the request's tools list, record an 'unknown_tool' entry in invalid_tool_call_arguments across chat_completions, responses, and messages paths.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
invalid_tool_call_arguments[].detailswas being stored as an already-JSON-stringified Zod error message (result.error.message) inside a JSONB column, resulting in doubly-encoded JSON. Switched toz.treeifyError(result.error)so schema mismatch details are structured data.unknown_toolerror kind: when the model emits a tool call whose name isn't in the request'stoolslist, we now record it ininvalid_tool_call_argumentsinstead of silently ignoring it. Wired into chat_completions, responses, and messages paths.toolCallArgumentErrorSchemaas adiscriminatedUniononkind:unparseable_json(string message),schema_mismatch(tree object),unknown_tool(no details).Verification
Visual Changes
N/A
Reviewer Notes
Stored shape of `api_request_log.error` changes for new rows: schema-mismatch `details` becomes a tree object instead of a JSON string, and a new `unknown_tool` variant may appear. Existing rows are unaffected (read paths don't parse `details`). For Anthropic messages, all tool names are tracked as known (including server tools like BashTool that have no `input_schema`) so builtins aren't falsely flagged.