@devries-cameron20 / composio-1 / commits / 48c839fac
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

fix: enforce z.object() for inputParams, flexible outputParams schema

- inputParams must be z.object() — throw ValidationError if not (tool inputs are always objects per OpenAI/Anthropic/Google tool calling APIs) - outputParams accepts any Zod type — stores full JSON Schema from zodToJsonSchema instead of assuming object shape Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

Dhawal Upadhyay committed Mar 17, 2026 at 15:14 UTC 48c839facf8151a7b7faaf7559e334771c3df2ee
1 file changed +10 -9
ts/packages/core/src/models/CustomTool.ts
+10 -9
@@ -127,6 +127,12 @@ export function createCustomTool<T extends z.ZodType>(
127 if (!options.inputParams) {
128 throw new ValidationError('createCustomTool: inputParams is required');
129 }
130 + if (!(options.inputParams instanceof z.ZodObject)) {
131 + throw new ValidationError(
132 + 'createCustomTool: inputParams must be a z.object() schema. ' +
133 + 'Tool input parameters are always an object with named properties.'
134 + );
135 + }
136 if (typeof options.execute !== 'function') {
137 throw new ValidationError('createCustomTool: execute must be a function');
138 }
@@ -136,7 +142,7 @@ export function createCustomTool<T extends z.ZodType>(
142
143 const { inputParams, execute } = options;
144
139 - // Convert Zod input schema → JSON Schema
145 + // Convert Zod input schema → JSON Schema (inputParams is guaranteed to be z.object)
146 const paramsSchema = zodToJsonSchema.default(inputParams, {
147 name: 'input',
148 }) as InputParamsSchema;
@@ -148,18 +154,13 @@ export function createCustomTool<T extends z.ZodType>(
154 ...(paramsSchemaJson.required ? { required: paramsSchemaJson.required } : {}),
155 };
156
151 - // Convert Zod output schema → JSON Schema (if provided)
157 + // Convert Zod output schema → JSON Schema (if provided, any Zod type allowed)
158 let outputSchema: Record<string, unknown> | undefined;
159 if (options.outputParams) {
160 const outSchema = zodToJsonSchema.default(options.outputParams, {
161 name: 'output',
156 - }) as { definitions: { output: { type: string; properties: Record<string, unknown>; required?: string[] } } };
157 - const outJson = outSchema.definitions.output;
158 - outputSchema = {
159 - type: 'object',
160 - properties: outJson.properties,
161 - ...(outJson.required ? { required: outJson.required } : {}),
162 - };
162 + }) as { definitions: { output: Record<string, unknown> } };
163 + outputSchema = outSchema.definitions.output;
164 }
165
166 return {