Skip to content

Fix: Preserve tool parameter descriptions in schema conversion#15945

Closed
trry-hub wants to merge 1 commit intoanomalyco:devfrom
trry-hub:fix/tool-argument-descriptions
Closed

Fix: Preserve tool parameter descriptions in schema conversion#15945
trry-hub wants to merge 1 commit intoanomalyco:devfrom
trry-hub:fix/tool-argument-descriptions

Conversation

@trry-hub
Copy link
Copy Markdown

@trry-hub trry-hub commented Mar 4, 2026

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

  • Replace z.toJSONSchema() with zodToJsonSchema() in packages/opencode/src/session/prompt.ts (line 788)
  • Add import for zodToJsonSchema from zod-to-json-schema package

Why This Fix?

  • z.toJSONSchema() is Zod's built-in method but doesn't preserve .describe() metadata
  • zodToJsonSchema() from zod-to-json-schema package correctly preserves all metadata
  • This aligns with the approach already used in server.ts

Impact

  • ✅ Minimal change (1 line + 1 import)
  • ✅ Consistent with existing codebase patterns
  • ✅ No breaking changes
  • ✅ Improves developer experience with custom tools

Testing

Created a test tool with parameter descriptions and verified that:

  1. Tool compiles without errors
  2. TypeScript type checking passes
  3. Parameter descriptions will be available to the LLM

Example

Before this fix:

// Tool definition
args: {
  text: z.string().describe("The text to process")
}
// LLM sees: just a string parameter, no description

After this fix:

// Tool definition
args: {
  text: z.string().describe("The text to process")
}
// LLM sees: string parameter with description "The text to process"

- 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.
@github-actions github-actions bot added the needs:compliance This means the issue will auto-close after 2 hours. label Mar 4, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 4, 2026

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

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.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 4, 2026

Hey! Your PR title Fix: Preserve tool parameter descriptions in schema conversion doesn't follow conventional commit format.

Please update it to start with one of:

  • feat: or feat(scope): new feature
  • fix: or fix(scope): bug fix
  • docs: or docs(scope): documentation changes
  • chore: or chore(scope): maintenance tasks
  • refactor: or refactor(scope): code refactoring
  • test: or test(scope): adding or updating tests

Where scope is the package name (e.g., app, desktop, opencode).

See CONTRIBUTING.md for details.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 4, 2026

The following comment was made by an LLM, it may be inaccurate:

Found Potential Duplicates

There are 2 related PRs addressing similar issues:

  1. PR fix(opencode): preserve custom tool arg descriptions in LLM prompts #13417 - fix(opencode): preserve custom tool arg descriptions in LLM prompts

  2. PR fix: preserve tool argument descriptions in schema conversion #14476 - fix: preserve tool argument descriptions in schema conversion

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.

@trry-hub
Copy link
Copy Markdown
Author

trry-hub commented Mar 4, 2026

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 z.toJSONSchema() with zodToJsonSchema() to preserve tool parameter descriptions.

Thanks to @Hemanshu-Upadhyay for the earlier contribution! 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs:compliance This means the issue will auto-close after 2 hours. needs:title

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tool argument descriptions lost in schema conversion

1 participant