Skip to content

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(vercel): keep optional parameters available under strict mode

jkomynofb30e8f299af
diff --git a/docs/content/docs/providers/vercel.mdx b/docs/content/docs/providers/vercel.mdx
index dee9ce02a..d8766b056 100644
--- a/docs/content/docs/providers/vercel.mdx
+++ b/docs/content/docs/providers/vercel.mdx
@@ -57,7 +57,7 @@ console.log(text);
## Provider specifics
-**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:
+**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:
```typescript
// @noErrors
diff --git a/ts/packages/providers/vercel/README.md b/ts/packages/providers/vercel/README.md
index 2b27e144e..373156c1b 100644
--- a/ts/packages/providers/vercel/README.md
+++ b/ts/packages/providers/vercel/README.md
@@ -45,7 +45,7 @@ For multi-turn conversations, store `session.sessionId` and reuse it with `compo
## Strict mode
-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:
+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:
```typescript
const composio = new Composio({ provider: new VercelProvider({ strict: true }) });
diff --git a/ts/packages/providers/vercel/src/index.ts b/ts/packages/providers/vercel/src/index.ts
index c0e7062f5..47d9ce9e3 100644
--- a/ts/packages/providers/vercel/src/index.ts
+++ b/ts/packages/providers/vercel/src/index.ts
@@ -17,11 +17,11 @@ import {
McpUrlResponse,
McpServerGetResponse,
deduplicateJsonSchemaRequiredArrays,
- dereferenceJsonSchema,
toStrictJsonSchema,
jsonSchemaToZodSchema,
logger,
normalizeToolArguments,
+ omitNullToolArguments,
} from '@composio/core';
import type { ToolSet as VercelToolSet, Tool as VercelTool } from 'ai';
import { tool } from 'ai';
@@ -112,27 +112,41 @@ export class VercelProvider extends BaseAgenticProvider<
wrapTool(composioTool: Tool, executeTool: ExecuteToolFn): VercelTool {
const inputParams = composioTool.inputParameters;
- let parameters: Record<string, unknown> = (inputParams ?? {}) as Record<string, unknown>;
- if (this.strict && inputParams?.type === 'object') {
- // Structured outputs reject schemas whose nested objects keep optional
- // properties or their own additionalProperties, so the strict contract
- // must be applied at every depth. Inline $ref/$defs first (lenient mode
- // keeps upstream schemas with dangling refs usable), then normalize.
- const dereferenced = dereferenceJsonSchema(parameters, {
- onUnresolved: 'sentinel',
- onReplace: ref =>
+ // Canonicalize required arrays at the vendor-schema emission boundary.
+ let parameters: Record<string, unknown> = deduplicateJsonSchemaRequiredArrays(
+ (inputParams ?? {}) as Record<string, unknown>
+ );
+ // Under strict mode optional parameters are emitted as required-nullable,
+ // so a `null` the tool's own schema does not accept means "omitted".
+ let strictSource: Record<string, unknown> | undefined;
+ if (this.strict && inputParams) {
+ // Structured outputs enforce their contract at every depth: all
+ // properties required, closed objects, no annotation keywords. The
+ // strict rewrite keeps every parameter (optional ones become nullable)
+ // and reports constructs it cannot express; such a tool keeps its
+ // original schema rather than a narrower one.
+ const strict = toStrictJsonSchema(inputParams);
+ if (strict.unsupported.length > 0) {
+ const reasons = strict.unsupported
+ .map(entry => `${entry.path || '<root>'}: ${entry.keyword} (${entry.detail})`)
+ .join('; ');
+ logger.warn(
+ `VercelProvider: tool "${composioTool.slug}" keeps its non-strict schema because it cannot be expressed as strict structured outputs: ${reasons}`
+ );
+ } else {
+ if (strict.totalChanges > 0) {
logger.debug(
- `VercelProvider: unresolved $ref "${ref}" in tool "${composioTool.slug}" replaced with a permissive schema`
- ),
- });
- parameters = toStrictJsonSchema<Record<string, unknown>>(dereferenced).schema;
+ `VercelProvider: strict mode rewrote ${strict.totalChanges} node(s) of tool "${composioTool.slug}": ${strict.changes
+ .map(change => `${change.path}: ${change.reason}`)
+ .join('; ')}`
+ );
+ }
+ parameters = strict.schema;
+ strictSource = strict.source;
+ }
}
- // Canonicalize required arrays at the vendor-schema emission boundary,
- // after any provider-specific schema transformations.
- const inputParametersSchema = jsonSchemaToZodSchema(
- deduplicateJsonSchemaRequiredArrays(parameters)
- );
+ const inputParametersSchema = jsonSchemaToZodSchema(parameters);
return tool({
description: composioTool.description,
@@ -140,9 +154,10 @@ export class VercelProvider extends BaseAgenticProvider<
execute: async params => {
// Models occasionally emit tool input as a JSON string rather than an object (issue #2406).
+ const normalized = normalizeToolArguments(params, composioTool.slug);
return await executeTool(
composioTool.slug,
- normalizeToolArguments(params, composioTool.slug)
+ strictSource ? omitNullToolArguments(normalized, strictSource) : normalized
);
},
});
diff --git a/ts/packages/providers/vercel/test/vercel.test.ts b/ts/packages/providers/vercel/test/vercel.test.ts
index 55478423e..9158f1acb 100644
--- a/ts/packages/providers/vercel/test/vercel.test.ts
+++ b/ts/packages/providers/vercel/test/vercel.test.ts
@@ -134,7 +134,7 @@ describe('VercelProvider', () => {
expect(mockExecuteToolFn).toHaveBeenCalledWith(mockTool.slug, params);
});
- it('enforces the strict contract on complex schemas when strict mode is enabled', () => {
+ it('keeps optional and nested parameters available under strict mode', () => {
const strictProvider = new VercelProvider({ strict: true });
const wrapped = strictProvider.wrapTool(
{
@@ -148,6 +148,7 @@ describe('VercelProvider', () => {
required: ['url'],
},
id: { type: ['string', 'null'] },
+ label: { type: 'string' },
},
required: ['cfg', 'id'],
},
@@ -157,13 +158,77 @@ describe('VercelProvider', () => {
const schema = wrapped.inputSchema as { safeParse: (value: unknown) => { success: boolean } };
- // Nested required key present, nullable field null — valid.
- expect(schema.safeParse({ cfg: { url: 'https://example.com' }, id: null }).success).toBe(
- true
+ // Optional parameters are still accepted, and may be null.
+ expect(
+ schema.safeParse({ cfg: { url: 'https://example.com', note: 'x' }, id: null, label: null })
+ .success
+ ).toBe(true);
+ // Every property is required under strict mode, so omitting one fails.
+ expect(schema.safeParse({ cfg: { url: 'https://example.com' }, id: 'a' }).success).toBe(
+ false
);
- // Nested optional property was dropped under strict mode, so a value for
- // it no longer parses.
- expect(schema.safeParse({ cfg: { note: 'x' }, id: 'a' }).success).toBe(false);
+ // Objects are closed, so unknown keys fail.
+ expect(
+ schema.safeParse({
+ cfg: { url: 'https://example.com', note: null, extra: 1 },
+ id: 'a',
+ label: null,
+ }).success
+ ).toBe(false);
+ });
+
+ it('omits null arguments before executing under strict mode', async () => {
+ const strictProvider = new VercelProvider({ strict: true });
+ const wrapped = strictProvider.wrapTool(
+ {
+ ...mockTool,
+ inputParameters: {
+ type: 'object',
+ properties: {
+ cfg: {
+ type: 'object',
+ properties: { url: { type: 'string' }, note: { type: 'string' } },
+ required: ['url'],
+ },
+ label: { type: 'string' },
+ },
+ required: ['cfg'],
+ },
+ },
+ mockExecuteToolFn
+ ) as unknown as MockedVercelTool;
+
+ await wrapped.execute(
+ { cfg: { url: 'https://example.com', note: null }, label: null },
+ { toolCallId: 'call_1', messages: [] }
+ );
+
+ expect(mockExecuteToolFn).toHaveBeenCalledWith(mockTool.slug, {
+ cfg: { url: 'https://example.com' },
+ });
+ });
+
+ it('keeps the original schema for tools strict mode cannot express', () => {
+ const strictProvider = new VercelProvider({ strict: true });
+ const wrapped = strictProvider.wrapTool(
+ {
+ ...mockTool,
+ inputParameters: {
+ type: 'object',
+ properties: {
+ headers: { type: 'object', additionalProperties: { type: 'string' } },
+ name: { type: 'string' },
+ },
+ required: ['headers'],
+ },
+ },
+ mockExecuteToolFn
+ ) as unknown as MockedVercelTool;
+
+ const schema = wrapped.inputSchema as { safeParse: (value: unknown) => { success: boolean } };
+
+ // `name` stays optional and `headers` still accepts arbitrary keys.
+ expect(schema.safeParse({ headers: { 'x-a': '1' } }).success).toBe(true);
});
});