Skip to content

fix: preserve tool argument descriptions in schema conversion#14476

Open
Hemanshu-Upadhyay wants to merge 1 commit intoanomalyco:devfrom
Hemanshu-Upadhyay:fix/tool-arg-descriptions
Open

fix: preserve tool argument descriptions in schema conversion#14476
Hemanshu-Upadhyay wants to merge 1 commit intoanomalyco:devfrom
Hemanshu-Upadhyay:fix/tool-arg-descriptions

Conversation

@Hemanshu-Upadhyay
Copy link
Copy Markdown

@Hemanshu-Upadhyay Hemanshu-Upadhyay commented Feb 20, 2026

Issue for this PR

Closes #4357

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Custom tools using .describe() on Zod schema properties lose those descriptions before they reach the LLM. This happens because session/prompt.ts uses z.toJSONSchema() which strips description metadata from schema properties.

The fix swaps it for zodToJsonSchema() from the zod-to-json-schema package, which correctly preserves .describe() metadata. This is the same function already used in server/routes/experimental.ts for the same purpose, and zod-to-json-schema is already a dependency.

How did you verify your code works?

  • Full typecheck passes (bun turbo typecheck — all 12 packages pass)
  • bun dev starts without issues
  • Verified zodToJsonSchema() output includes description fields for properties with .describe(), while z.toJSONSchema() drops them

Screenshots / recordings

Not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Use zodToJsonSchema() instead of z.toJSONSchema() for converting tool
parameter schemas, which correctly preserves .describe() metadata on
Zod schema properties. This ensures custom tool argument descriptions
are passed through to the LLM.

Fixes anomalyco#4357
@github-actions github-actions bot added the needs:compliance This means the issue will auto-close after 2 hours. label Feb 20, 2026
@github-actions
Copy link
Copy Markdown
Contributor

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

Based on my search, I found a potentially related PR:

Related PR Found:

This PR appears to address the same issue—preserving custom tool argument descriptions. It may be worth checking if it was already merged or closed, and whether the current PR (#14476) is a follow-up, alternative approach, or if they're addressing different aspects of the same problem.

@github-actions github-actions bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Feb 20, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@jbmml
Copy link
Copy Markdown

jbmml commented Apr 3, 2026

Heads up — switching from z.toJSONSchema() to zodToJsonSchema() would introduce a regression on the current codebase. zod-to-json-schema@3.24.5 is incompatible with Zod v4 — it returns {"type":"string"} for object schemas, losing all properties and descriptions. I verified this directly.

The actual root cause for plugin tools losing descriptions is cross-Zod-instance metadata loss (Zod v4 stores .describe() in a per-instance globalRegistry). PR #15957 has the correct fix for this.

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.

Tool argument descriptions lost in schema conversion

2 participants