Fix: Preserve tool parameter descriptions in schema conversion#15945
Fix: Preserve tool parameter descriptions in schema conversion#15945trry-hub wants to merge 1 commit intoanomalyco:devfrom
Conversation
- Replace z.toJSONSchema() with zodToJsonSchema() in prompt.ts - Ensures .describe() metadata is properly passed to LLM - Fixes anomalyco#4357 The z.toJSONSchema() method was dropping .describe() metadata from tool parameters, causing the LLM to not understand what the parameters are for. This change aligns with the approach already used in server.ts.
|
This PR doesn't fully meet our contributing guidelines and PR template. What needs to be fixed:
Please edit this PR description to address the above within 2 hours, or it will be automatically closed. If you believe this was flagged incorrectly, please let a maintainer know. |
|
Hey! Your PR title Please update it to start with one of:
Where See CONTRIBUTING.md for details. |
|
The following comment was made by an LLM, it may be inaccurate: Found Potential DuplicatesThere are 2 related PRs addressing similar issues:
These PRs appear to address the same or very similar issue - preserving tool parameter/argument descriptions. PR #14476 in particular has an identical title focus on schema conversion. You should review whether these PRs were already merged, closed, or if #15945 supersedes them with additional fixes. |
|
Closing this PR in favor of #14476 which has identical changes and was submitted earlier on 2026-02-20. Both PRs fix the same issue (#4357) with the same code changes - replacing Thanks to @Hemanshu-Upadhyay for the earlier contribution! 🙏 |
Summary
Fixes #4357
This PR fixes an issue where tool parameter descriptions (
.describe()) were being lost during schema conversion, preventing the LLM from understanding what tool parameters are for.Changes
z.toJSONSchema()withzodToJsonSchema()inpackages/opencode/src/session/prompt.ts(line 788)zodToJsonSchemafromzod-to-json-schemapackageWhy This Fix?
z.toJSONSchema()is Zod's built-in method but doesn't preserve.describe()metadatazodToJsonSchema()fromzod-to-json-schemapackage correctly preserves all metadataserver.tsImpact
Testing
Created a test tool with parameter descriptions and verified that:
Example
Before this fix:
After this fix: