Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
Mirrored from https://github.com/Camo67/composio.git
Synced Nov 21, 14:45 UTC
fix(vercel): keep optional parameters available under strict mode
VercelProvider strict mode now widens optional parameters to nullable instead of dropping them, keeps the original schema for tools strict mode cannot express, and drops null arguments the tool schema rejects before execution. The README and docs page described the old dropping behavior. Co-authored-by: AseemPrasad <aseemprasad0520@gmail.com> Claude-Session: https://claude.ai/code/session_01TDrxCHn2hg51HmxVstSUgs
jkomyno committed
Aug 26, 2026 at 17:19 UTC
fb30e8f299af548de76dba874f4278d14757f1e1
4 files changed
+109
-29
docs/content/docs/providers/vercel.mdx
+1
-1
@@ -57,7 +57,7 @@ console.log(text);
57
58
## Provider specifics
59
60
-**Strict mode.** Some models reject tool schemas that contain optional parameters. Pass `strict: true` to the provider to drop every non-required property from each tool's input schema before it reaches the AI SDK:
60
+**Strict mode.** Some models reject tool schemas that contain optional parameters. Pass `strict: true` to the provider to normalize each tool's input schema for OpenAI structured outputs before it reaches the AI SDK: every object lists all of its properties in `required` and is closed, and optional properties stay available but accept `null`. A `null` the model sends for an optional parameter is dropped before the tool runs. Tools whose schema cannot be expressed in strict mode (objects that accept arbitrary keys, `allOf`, `prefixItems`) keep their original schema and log a warning:
61
62
```typescript
63
// @noErrors
ts/packages/providers/vercel/README.md
+1
-1
@@ -45,7 +45,7 @@ For multi-turn conversations, store `session.sessionId` and reuse it with `compo
45
46
## Strict mode
47
48
-Some models reject tool schemas that contain optional parameters. Pass `strict: true` to drop every non-required property from each tool's input schema before it reaches the AI SDK:
48
+Some models reject tool schemas that contain optional parameters. Pass `strict: true` to normalize each tool's input schema for OpenAI structured outputs before it reaches the AI SDK: every object lists all of its properties in `required` and is closed, and optional properties stay available but accept `null`. A `null` the model sends for an optional parameter is dropped before the tool runs. Tools whose schema cannot be expressed in strict mode (objects that accept arbitrary keys, `allOf`, `prefixItems`) keep their original schema and log a warning:
49
50
```typescript
51
const composio = new Composio({ provider: new VercelProvider({ strict: true }) });
ts/packages/providers/vercel/src/index.ts
+35
-20
@@ -17,11 +17,11 @@ import {
17
McpUrlResponse,
18
McpServerGetResponse,
19
deduplicateJsonSchemaRequiredArrays,
20
- dereferenceJsonSchema,
20
toStrictJsonSchema,
21
jsonSchemaToZodSchema,
22
logger,
23
normalizeToolArguments,
24
+ omitNullToolArguments,
25
} from '@composio/core';
26
import type { ToolSet as VercelToolSet, Tool as VercelTool } from 'ai';
27
import { tool } from 'ai';
@@ -112,27 +112,41 @@ export class VercelProvider extends BaseAgenticProvider<
112
wrapTool(composioTool: Tool, executeTool: ExecuteToolFn): VercelTool {
113
const inputParams = composioTool.inputParameters;
114
115
- let parameters: Record<string, unknown> = (inputParams ?? {}) as Record<string, unknown>;
116
- if (this.strict && inputParams?.type === 'object') {
117
- // Structured outputs reject schemas whose nested objects keep optional
118
- // properties or their own additionalProperties, so the strict contract
119
- // must be applied at every depth. Inline $ref/$defs first (lenient mode
120
- // keeps upstream schemas with dangling refs usable), then normalize.
121
- const dereferenced = dereferenceJsonSchema(parameters, {
122
- onUnresolved: 'sentinel',
123
- onReplace: ref =>
115
+ // Canonicalize required arrays at the vendor-schema emission boundary.
116
+ let parameters: Record<string, unknown> = deduplicateJsonSchemaRequiredArrays(
117
+ (inputParams ?? {}) as Record<string, unknown>
118
+ );
119
+ // Under strict mode optional parameters are emitted as required-nullable,
120
+ // so a `null` the tool's own schema does not accept means "omitted".
121
+ let strictSource: Record<string, unknown> | undefined;
122
+ if (this.strict && inputParams) {
123
+ // Structured outputs enforce their contract at every depth: all
124
+ // properties required, closed objects, no annotation keywords. The
125
+ // strict rewrite keeps every parameter (optional ones become nullable)
126
+ // and reports constructs it cannot express; such a tool keeps its
127
+ // original schema rather than a narrower one.
128
+ const strict = toStrictJsonSchema(inputParams);
129
+ if (strict.unsupported.length > 0) {
130
+ const reasons = strict.unsupported
131
+ .map(entry => `${entry.path || '<root>'}: ${entry.keyword} (${entry.detail})`)
132
+ .join('; ');
133
+ logger.warn(
134
+ `VercelProvider: tool "${composioTool.slug}" keeps its non-strict schema because it cannot be expressed as strict structured outputs: ${reasons}`
135
+ );
136
+ } else {
137
+ if (strict.totalChanges > 0) {
138
logger.debug(
125
- `VercelProvider: unresolved $ref "${ref}" in tool "${composioTool.slug}" replaced with a permissive schema`
126
- ),
127
- });
128
- parameters = toStrictJsonSchema<Record<string, unknown>>(dereferenced).schema;
139
+ `VercelProvider: strict mode rewrote ${strict.totalChanges} node(s) of tool "${composioTool.slug}": ${strict.changes
140
+ .map(change => `${change.path}: ${change.reason}`)
141
+ .join('; ')}`
142
+ );
143
+ }
144
+ parameters = strict.schema;
145
+ strictSource = strict.source;
146
+ }
147
}
148
131
- // Canonicalize required arrays at the vendor-schema emission boundary,
132
- // after any provider-specific schema transformations.
133
- const inputParametersSchema = jsonSchemaToZodSchema(
134
- deduplicateJsonSchemaRequiredArrays(parameters)
135
- );
149
+ const inputParametersSchema = jsonSchemaToZodSchema(parameters);
150
151
return tool({
152
description: composioTool.description,
@@ -140,9 +154,10 @@ export class VercelProvider extends BaseAgenticProvider<
154
155
execute: async params => {
156
// Models occasionally emit tool input as a JSON string rather than an object (issue #2406).
157
+ const normalized = normalizeToolArguments(params, composioTool.slug);
158
return await executeTool(
159
composioTool.slug,
145
- normalizeToolArguments(params, composioTool.slug)
160
+ strictSource ? omitNullToolArguments(normalized, strictSource) : normalized
161
);
162
},
163
});
ts/packages/providers/vercel/test/vercel.test.ts
+72
-7
@@ -134,7 +134,7 @@ describe('VercelProvider', () => {
134
expect(mockExecuteToolFn).toHaveBeenCalledWith(mockTool.slug, params);
135
});
136
137
- it('enforces the strict contract on complex schemas when strict mode is enabled', () => {
137
+ it('keeps optional and nested parameters available under strict mode', () => {
138
const strictProvider = new VercelProvider({ strict: true });
139
const wrapped = strictProvider.wrapTool(
140
{
@@ -148,6 +148,7 @@ describe('VercelProvider', () => {
148
required: ['url'],
149
},
150
id: { type: ['string', 'null'] },
151
+ label: { type: 'string' },
152
},
153
required: ['cfg', 'id'],
154
},
@@ -157,13 +158,77 @@ describe('VercelProvider', () => {
158
159
const schema = wrapped.inputSchema as { safeParse: (value: unknown) => { success: boolean } };
160
160
- // Nested required key present, nullable field null — valid.
161
- expect(schema.safeParse({ cfg: { url: 'https://example.com' }, id: null }).success).toBe(
162
- true
161
+ // Optional parameters are still accepted, and may be null.
162
+ expect(
163
+ schema.safeParse({ cfg: { url: 'https://example.com', note: 'x' }, id: null, label: null })
164
+ .success
165
+ ).toBe(true);
166
+ // Every property is required under strict mode, so omitting one fails.
167
+ expect(schema.safeParse({ cfg: { url: 'https://example.com' }, id: 'a' }).success).toBe(
168
+ false
169
);
164
- // Nested optional property was dropped under strict mode, so a value for
165
- // it no longer parses.
166
- expect(schema.safeParse({ cfg: { note: 'x' }, id: 'a' }).success).toBe(false);
170
+ // Objects are closed, so unknown keys fail.
171
+ expect(
172
+ schema.safeParse({
173
+ cfg: { url: 'https://example.com', note: null, extra: 1 },
174
+ id: 'a',
175
+ label: null,
176
+ }).success
177
+ ).toBe(false);
178
+ });
179
+
180
+ it('omits null arguments before executing under strict mode', async () => {
181
+ const strictProvider = new VercelProvider({ strict: true });
182
+ const wrapped = strictProvider.wrapTool(
183
+ {
184
+ ...mockTool,
185
+ inputParameters: {
186
+ type: 'object',
187
+ properties: {
188
+ cfg: {
189
+ type: 'object',
190
+ properties: { url: { type: 'string' }, note: { type: 'string' } },
191
+ required: ['url'],
192
+ },
193
+ label: { type: 'string' },
194
+ },
195
+ required: ['cfg'],
196
+ },
197
+ },
198
+ mockExecuteToolFn
199
+ ) as unknown as MockedVercelTool;
200
+
201
+ await wrapped.execute(
202
+ { cfg: { url: 'https://example.com', note: null }, label: null },
203
+ { toolCallId: 'call_1', messages: [] }
204
+ );
205
+
206
+ expect(mockExecuteToolFn).toHaveBeenCalledWith(mockTool.slug, {
207
+ cfg: { url: 'https://example.com' },
208
+ });
209
+ });
210
+
211
+ it('keeps the original schema for tools strict mode cannot express', () => {
212
+ const strictProvider = new VercelProvider({ strict: true });
213
+ const wrapped = strictProvider.wrapTool(
214
+ {
215
+ ...mockTool,
216
+ inputParameters: {
217
+ type: 'object',
218
+ properties: {
219
+ headers: { type: 'object', additionalProperties: { type: 'string' } },
220
+ name: { type: 'string' },
221
+ },
222
+ required: ['headers'],
223
+ },
224
+ },
225
+ mockExecuteToolFn
226
+ ) as unknown as MockedVercelTool;
227
+
228
+ const schema = wrapped.inputSchema as { safeParse: (value: unknown) => { success: boolean } };
229
+
230
+ // `name` stays optional and `headers` still accepts arbitrary keys.
231
+ expect(schema.safeParse({ headers: { 'x-a': '1' } }).success).toBe(true);
232
});
233
});
234