Skip to content

fix(ai-gateway): improve tool call error reporting#2815

Open
kilo-code-bot[bot] wants to merge 2 commits intomainfrom
fix/invalid-tool-call-args-no-double-encode
Open

fix(ai-gateway): improve tool call error reporting#2815
kilo-code-bot[bot] wants to merge 2 commits intomainfrom
fix/invalid-tool-call-args-no-double-encode

Conversation

@kilo-code-bot
Copy link
Copy Markdown
Contributor

@kilo-code-bot kilo-code-bot Bot commented Apr 25, 2026

Summary

  • invalid_tool_call_arguments[].details was being stored as an already-JSON-stringified Zod error message (result.error.message) inside a JSONB column, resulting in doubly-encoded JSON. Switched to z.treeifyError(result.error) so schema mismatch details are structured data.
  • Added a new unknown_tool error kind: when the model emits a tool call whose name isn't in the request's tools list, we now record it in invalid_tool_call_arguments instead of silently ignoring it. Wired into chat_completions, responses, and messages paths.
  • Modelled toolCallArgumentErrorSchema as a discriminatedUnion on kind: unparseable_json (string message), schema_mismatch (tree object), unknown_tool (no details).

Verification

  • `pnpm typecheck`

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.

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.
@kilo-code-bot
Copy link
Copy Markdown
Contributor Author

kilo-code-bot Bot commented Apr 25, 2026

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (1 files)
  • apps/web/src/lib/ai-gateway/api-request-log-errors.ts

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.
@kilo-code-bot kilo-code-bot Bot changed the title fix(ai-gateway): avoid double JSON encoding in tool call error details fix(ai-gateway): improve tool call error reporting Apr 25, 2026
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.

1 participant