fix(llm): include expected and received keys in tool schema error message#30224
fix(llm): include expected and received keys in tool schema error message#30224nikhilkulkarni1755 wants to merge 1 commit into
Conversation
|
The following comment was made by an LLM, it may be inaccurate: Based on my search, the only potentially related PR is:
However, these are complementary fixes addressing different aspects of the same issue, not duplicates of PR #30224. The current PR specifically fixes the error message display to help models self-correct, while those PRs prevent/clean up the mismatch scenario. No duplicate PRs found |
f336578 to
6bb8bf0
Compare
edae9ad to
e0f9b8d
Compare
…sage When a local model sends wrong argument keys to a tool the error fed back only said "Invalid tool input: Missing key at ["content"]". The model has no signal about what keys to use, so it retries identically and hits the doom loop. Adds expected and received keys to the error so the model can self-correct on the next turn. Also resolves Effect's $defs/$ref JSON schema shape for multi-field structs so the expected keys are extracted correctly. Fixes anomalyco#29142
e0f9b8d to
797837f
Compare
Issue for this PR
Closes #29142
Related to #18131 (original report, March 2026)
Type of change
What does this PR do?
When a local model sends wrong argument keys to a tool — e.g.
fileContentinstead ofcontentfor the write tool — the error fed back only saysInvalid tool input: Missing key at ["content"]. The model has no idea what keys to use, so it retries identically and hits the doom loop.This fixes the error message to include expected keys and received keys, so the model can self-correct on the next turn. The error is built in
tool-runtime.ts(the dispatch layer), not individual tool definitions — that's where schema validation happens across all tools.One implementation detail: Effect's JSON schema generator wraps multi-field structs in
$defs/$ref(see tool.ts line 183), so readinginputSchema.propertiesdirectly is empty for tools with more than one parameter. The helper resolves both shapes.Complementary to #29943 (field reorder, still open) and #30091 (settle pending parts, still open) — those prevent the mismatch and clean up DB state; this fixes what the model sees when it goes wrong anyway.
How did you verify your code works?
Ran
bun test(full llm package) inside an Orbstack Ubuntu 24.04 container (Bun 1.3.14): 260 pass, 23 skip, 0 fail.Added 3 tests covering the failure modes from the bug reports:
fileContent/pathvscontent/filePath)Checklist