Skip to content

fix(tools): validate model tool input before invocation - #76

Open
imMamdouhaboammar wants to merge 3 commits into
MagicCube:mainfrom
imMamdouhaboammar:fix/tool-runtime-validation
Open

fix(tools): validate model tool input before invocation#76
imMamdouhaboammar wants to merge 3 commits into
MagicCube:mainfrom
imMamdouhaboammar:fix/tool-runtime-validation

Conversation

@imMamdouhaboammar

Copy link
Copy Markdown

Summary

Make defineTool() enforce its Zod parameter schema at runtime before calling the tool implementation.

Root cause

Every Helixent tool declares a Zod schema, but defineTool() previously returned the raw implementation unchanged. The schema was therefore only used as model-facing metadata and TypeScript inference. Model tool arguments are runtime data, so malformed or missing fields could reach implementations that assume the inferred type is already true, producing avoidable exceptions or inconsistent behavior.

Changes

  • parse every tool invocation through its declared Zod schema
  • call the implementation only with validated/transformed input
  • preserve AbortSignal forwarding unchanged
  • keep the public typed FunctionTool.invoke contract intact
  • add co-located regression tests proving malformed input is rejected before implementation, schema transforms are applied, and signals still propagate

This turns the existing tool schema into the actual runtime boundary instead of trusting model-generated arguments to satisfy compile-time types.

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