Description
When using the AI SDK tools from @supermemory/tools, calls to searchMemories and documentList fail with a validation error when the LLM generates limit or offset as a string instead of a number:
tool call validation failed: parameters for tool searchMemories did not match schema: errors: [`/limit`: expected number, but got string]
Root Cause
The zod schemas for searchMemories and documentList define limit and offset as z.number(). However, LLMs occasionally emit numeric parameters as JSON strings (e.g., "10" instead of 10). z.number() rejects strings, while z.coerce.number() would silently coerce them.
Affected Fields
| Tool |
Field |
Current Schema |
searchMemories |
limit |
z.number().optional().default(10) |
documentList |
limit |
z.number().optional().default(10) |
documentList |
offset |
z.number().optional() |
Fix
Change z.number() → z.coerce.number() in packages/tools/src/ai-sdk.ts for all three fields.
z.coerce.number() is a standard Zod v4 pattern that converts string inputs to numbers during validation. If the value is already a number, it passes through unchanged. If it is undefined (for optional fields), it remains undefined. Only string-form numbers get coerced.
Relevant Code
https://github.com/supermemoryai/supermemory/blob/main/packages/tools/src/ai-sdk.ts
Environment
@supermemory/tools: 2.0.0
zod: ^4.1.5
- Used via
@supermemory/tools/ai-sdk export
Description
When using the AI SDK tools from
@supermemory/tools, calls tosearchMemoriesanddocumentListfail with a validation error when the LLM generateslimitoroffsetas a string instead of a number:Root Cause
The zod schemas for
searchMemoriesanddocumentListdefinelimitandoffsetasz.number(). However, LLMs occasionally emit numeric parameters as JSON strings (e.g.,"10"instead of10).z.number()rejects strings, whilez.coerce.number()would silently coerce them.Affected Fields
searchMemorieslimitz.number().optional().default(10)documentListlimitz.number().optional().default(10)documentListoffsetz.number().optional()Fix
Change
z.number()→z.coerce.number()inpackages/tools/src/ai-sdk.tsfor all three fields.z.coerce.number()is a standard Zod v4 pattern that converts string inputs to numbers during validation. If the value is already a number, it passes through unchanged. If it isundefined(for optional fields), it remains undefined. Only string-form numbers get coerced.Relevant Code
https://github.com/supermemoryai/supermemory/blob/main/packages/tools/src/ai-sdk.ts
Environment
@supermemory/tools: 2.0.0zod: ^4.1.5@supermemory/tools/ai-sdkexport