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(json-schema): integrate Google object type normalization

sergioperezchecoa2f6b9699b75
diff --git a/.changeset/ensure-object-type-on-properties.md b/.changeset/ensure-object-type-on-properties.md
new file mode 100644
index 000000000..6bc3ab9ba
--- /dev/null
+++ b/.changeset/ensure-object-type-on-properties.md
@@ -0,0 +1,5 @@
+---
+'@composio/core': patch
+---
+
+Add `type: "object"` to nested JSON Schema nodes that carry `properties` without an explicit type, so tool schemas work with strict OpenAPI 3.0 consumers like Google Gemini.
diff --git a/.changeset/normalize-google-object-types.md b/.changeset/normalize-google-object-types.md
new file mode 100644
index 000000000..b5d9ccc23
--- /dev/null
+++ b/.changeset/normalize-google-object-types.md
@@ -0,0 +1,5 @@
+---
+'@composio/google': patch
+---
+
+Add missing object types to nested Google GenAI tool schemas so Gemini accepts function declarations with property maps. This release requires `@composio/core >=0.16.0 <1.0.0` for the shared schema normalizer.
diff --git a/docs/content/changelog/08-06-26-free-form-tool-arguments.mdx b/docs/content/changelog/08-06-26-free-form-tool-arguments.mdx
index 2574f5046..c68fe03bd 100644
--- a/docs/content/changelog/08-06-26-free-form-tool-arguments.mdx
+++ b/docs/content/changelog/08-06-26-free-form-tool-arguments.mdx
@@ -13,6 +13,7 @@ date: '2026-08-06'
| TypeScript `@composio/slim` | `0.16.0` |
| TypeScript `@composio/json-schema-to-zod` | `0.3.0` |
| TypeScript `@composio/claude-agent-sdk` | `0.11.0` |
+| TypeScript `@composio/google` | `0.10.2` |
---
@@ -22,6 +23,10 @@ A tool argument declared as a bare `{"type": "object"}` — with no `properties`
An object schema that names no properties is now treated as open, unless it sets `additionalProperties: false`: arbitrary content is accepted and preserved, at the root, nested inside another object, and inside array items.
+#### Google Gemini schema compatibility
+
+`@composio/google` now adds `type: "object"` to schema nodes that declare `properties` without a type before emitting Google GenAI function declarations. The normalization follows only schema-bearing keywords, so property maps — including a field literally named `properties` — and instance values under `const`, `default`, `enum`, and `examples` remain unchanged. This provider release requires `@composio/core >=0.16.0 <1.0.0`.
+
**Before:**
```python
diff --git a/ts/packages/core/src/index.ts b/ts/packages/core/src/index.ts
index 054b8fb7b..874d7b023 100644
--- a/ts/packages/core/src/index.ts
+++ b/ts/packages/core/src/index.ts
@@ -7,6 +7,7 @@ export type { BaseComposioProvider } from './provider/BaseProvider';
export {
dereferenceJsonSchema,
deduplicateJsonSchemaRequiredArrays,
+ ensureObjectTypeOnProperties,
jsonSchemaToZodSchema,
removeNonRequiredProperties,
} from './utils/jsonSchema';
diff --git a/ts/packages/core/src/utils/jsonSchema.ts b/ts/packages/core/src/utils/jsonSchema.ts
index 1e3c48e80..657600117 100644
--- a/ts/packages/core/src/utils/jsonSchema.ts
+++ b/ts/packages/core/src/utils/jsonSchema.ts
@@ -258,6 +258,91 @@ export function dereferenceJsonSchema<T = unknown>(
return out as T;
}
+/**
+ * Returns a deep-cloned JSON Schema in which every node that carries a
+ * `properties` keyword also carries `type: "object"` when it has no explicit
+ * `type`. OpenAI tolerates the omission, but Google Gemini enforces OpenAPI
+ * 3.0 strictly and rejects function declarations whose nested objects are
+ * missing the `type` (see https://github.com/ComposioHQ/composio/issues/4022).
+ *
+ * The function follows JSON Schema's schema-bearing keywords while keeping
+ * property maps and instance values as containers. Nodes that already declare
+ * a `type` are left untouched.
+ */
+export function ensureObjectTypeOnProperties<T = unknown>(schema: T): T {
+ type WalkMode = 'schema' | 'schema-array' | 'schema-map' | 'dependencies-map' | 'value';
+
+ const schemaKeywords = new Set([
+ 'additionalItems',
+ 'additionalProperties',
+ 'contains',
+ 'contentSchema',
+ 'else',
+ 'if',
+ 'not',
+ 'propertyNames',
+ 'then',
+ 'unevaluatedItems',
+ 'unevaluatedProperties',
+ ]);
+ const schemaArrayKeywords = new Set(['allOf', 'anyOf', 'oneOf', 'prefixItems']);
+ const schemaMapKeywords = new Set([
+ '$defs',
+ 'definitions',
+ 'dependentSchemas',
+ 'patternProperties',
+ 'properties',
+ ]);
+
+ function walk(value: unknown, mode: WalkMode, depth = 0): unknown {
+ if (depth > MAX_NODE_DEPTH) {
+ throw new RangeError(`JSON Schema exceeds maximum nesting depth of ${MAX_NODE_DEPTH}`);
+ }
+
+ if (Array.isArray(value)) {
+ const itemMode = mode === 'schema-array' ? 'schema' : 'value';
+ return value.map(item => walk(item, itemMode, depth + 1));
+ }
+
+ if (!isPlainObject(value)) return value;
+
+ const clone: Record<string, unknown> = {};
+ for (const [key, child] of Object.entries(value)) {
+ let childMode: WalkMode = 'value';
+ if (mode === 'schema-map') {
+ childMode = 'schema';
+ } else if (mode === 'dependencies-map') {
+ childMode = Array.isArray(child) ? 'value' : 'schema';
+ } else if (mode === 'schema') {
+ if (schemaMapKeywords.has(key)) {
+ childMode = 'schema-map';
+ } else if (schemaArrayKeywords.has(key) || (key === 'items' && Array.isArray(child))) {
+ childMode = 'schema-array';
+ } else if (schemaKeywords.has(key) || key === 'items') {
+ childMode = 'schema';
+ } else if (key === 'dependencies') {
+ childMode = 'dependencies-map';
+ }
+ }
+
+ Object.defineProperty(clone, key, {
+ configurable: true,
+ enumerable: true,
+ value: walk(child, childMode, depth + 1),
+ writable: true,
+ });
+ }
+
+ if (mode === 'schema' && clone.properties !== undefined && clone.type === undefined) {
+ clone.type = 'object';
+ }
+
+ return clone;
+ }
+
+ return walk(schema, 'schema') as T;
+}
+
/**
* Returns a deep-cloned JSON Schema whose `required` arrays contain each entry
* at most once. Duplicate entries are invalid in JSON Schema 2020-12 but do
diff --git a/ts/packages/core/test/utils/jsonSchema.test.ts b/ts/packages/core/test/utils/jsonSchema.test.ts
index 029bc2dd2..8258d4556 100644
--- a/ts/packages/core/test/utils/jsonSchema.test.ts
+++ b/ts/packages/core/test/utils/jsonSchema.test.ts
@@ -2,6 +2,7 @@ import { describe, it, expect, vi } from 'vitest';
import {
deduplicateJsonSchemaRequiredArrays,
dereferenceJsonSchema,
+ ensureObjectTypeOnProperties,
} from '../../src/utils/jsonSchema';
import { JsonSchemaRefResolutionError } from '../../src/errors/ValidationErrors';
import logger from '../../src/utils/logger';
@@ -686,3 +687,182 @@ describe('shared corpus invariants', () => {
expect(() => assertCorpusInvariants([declared])).not.toThrow();
});
});
+
+describe('ensureObjectTypeOnProperties', () => {
+ it('adds type:object to nested nodes that have properties but no type', () => {
+ const schema = {
+ type: 'object',
+ properties: {
+ target: {
+ properties: {
+ name: { type: 'string' },
+ },
+ },
+ },
+ };
+
+ const result = ensureObjectTypeOnProperties(schema);
+ expect(result).toEqual({
+ type: 'object',
+ properties: {
+ target: {
+ type: 'object',
+ properties: {
+ name: { type: 'string' },
+ },
+ },
+ },
+ });
+ });
+
+ it('leaves nodes that already declare a type untouched', () => {
+ const schema = {
+ type: 'object',
+ properties: {
+ target: {
+ type: 'object',
+ properties: { name: { type: 'string' } },
+ },
+ },
+ };
+
+ const result = ensureObjectTypeOnProperties(schema);
+ expect(result).toEqual(schema);
+ });
+
+ it('handles deeply nested properties inside array items', () => {
+ const schema = {
+ type: 'object',
+ properties: {
+ list: {
+ type: 'array',
+ items: {
+ properties: { id: { type: 'string' } },
+ },
+ },
+ },
+ };
+
+ const result = ensureObjectTypeOnProperties(schema) as typeof schema;
+ expect(result.properties.list.items).toHaveProperty('type', 'object');
+ });
+
+ it('does not mutate the input schema', () => {
+ const schema = {
+ type: 'object',
+ properties: {
+ target: { properties: { name: { type: 'string' } } },
+ },
+ };
+
+ ensureObjectTypeOnProperties(schema);
+ expect(schema.properties.target).not.toHaveProperty('type');
+ });
+
+ it('does not inject type:object into instance-value keywords (const, default, enum, examples)', () => {
+ const schema = {
+ type: 'object',
+ properties: {
+ choice: {
+ type: 'object',
+ properties: { id: { type: 'string' } },
+ default: { properties: { should_not_gain_type: true } },
+ const: { properties: { marker: true } },
+ examples: [{ properties: { marker: true } }],
+ enum: [{ properties: { marker: true } }],
+ },
+ },
+ };
+
+ const result = ensureObjectTypeOnProperties(schema) as typeof schema;
+ const choice = result.properties.choice as Record<string, unknown>;
+ expect((choice.default as Record<string, unknown>).type).toBeUndefined();
+ expect((choice.const as Record<string, unknown>).type).toBeUndefined();
+ expect((choice.examples as Record<string, unknown>[])[0].type).toBeUndefined();
+ expect((choice.enum as Record<string, unknown>[])[0].type).toBeUndefined();
+ });
+
+ it('does not treat a properties map as a schema when a field is named properties', () => {
+ const schema = {
+ type: 'object',
+ properties: {
+ properties: {
+ properties: {
+ name: { type: 'string' },
+ },
+ },
+ },
+ };
+
+ const result = ensureObjectTypeOnProperties(schema) as {
+ properties: Record<string, unknown>;
+ };
+
+ expect(result.properties).toEqual({
+ properties: {
+ type: 'object',
+ properties: {
+ name: { type: 'string' },
+ },
+ },
+ });
+ expect(result.properties).not.toHaveProperty('type');
+ });
+
+ it('preserves reserved property names without changing the property-map prototype', () => {
+ const propertySchemas: Record<string, unknown> = {};
+ for (const key of ['constructor', 'prototype', '__proto__']) {
+ Object.defineProperty(propertySchemas, key, {
+ configurable: true,
+ enumerable: true,
+ value: { properties: { value: { type: 'string' } } },
+ writable: true,
+ });
+ }
+
+ const result = ensureObjectTypeOnProperties({
+ type: 'object',
+ properties: propertySchemas,
+ });
+
+ expect(Object.getPrototypeOf(result.properties)).toBe(Object.prototype);
+ for (const key of ['constructor', 'prototype', '__proto__']) {
+ expect(Object.hasOwn(result.properties, key)).toBe(true);
+ expect(result.properties[key]).toEqual({
+ type: 'object',
+ properties: { value: { type: 'string' } },
+ });
+ }
+ });
+
+ it('preserves reserved keys in instance defaults without treating their values as schemas', () => {
+ const defaultValue: Record<string, unknown> = {};
+ for (const key of ['constructor', 'prototype', '__proto__']) {
+ Object.defineProperty(defaultValue, key, {
+ configurable: true,
+ enumerable: true,
+ value: { properties: { marker: true } },
+ writable: true,
+ });
+ }
+
+ const result = ensureObjectTypeOnProperties({
+ type: 'object',
+ properties: {
+ choice: {
+ type: 'object',
+ properties: {},
+ default: defaultValue,
+ },
+ },
+ });
+ const normalizedDefault = result.properties.choice.default;
+
+ expect(Object.getPrototypeOf(normalizedDefault)).toBe(Object.prototype);
+ for (const key of ['constructor', 'prototype', '__proto__']) {
+ expect(Object.hasOwn(normalizedDefault, key)).toBe(true);
+ expect(normalizedDefault[key]).toEqual({ properties: { marker: true } });
+ expect(normalizedDefault[key]).not.toHaveProperty('type');
+ }
+ });
+});
diff --git a/ts/packages/providers/google/package.json b/ts/packages/providers/google/package.json
index 94e89bd7f..2e197d182 100644
--- a/ts/packages/providers/google/package.json
+++ b/ts/packages/providers/google/package.json
@@ -43,7 +43,7 @@
"author": "",
"license": "ISC",
"peerDependencies": {
- "@composio/core": ">=0.10.0 <1.0.0",
+ "@composio/core": ">=0.16.0 <1.0.0",
"@google/genai": "^1.1.0"
},
"devDependencies": {
diff --git a/ts/packages/providers/google/src/index.ts b/ts/packages/providers/google/src/index.ts
index f669ceeb4..e5104821f 100644
--- a/ts/packages/providers/google/src/index.ts
+++ b/ts/packages/providers/google/src/index.ts
@@ -17,6 +17,7 @@ import {
McpServerGetResponse,
normalizeToolArguments,
deduplicateJsonSchemaRequiredArrays,
+ ensureObjectTypeOnProperties,
} from '@composio/core';
import { FunctionDeclaration, Schema } from '@google/genai';
@@ -128,7 +129,9 @@ export class GoogleProvider extends BaseNonAgenticProvider<
* ```
*/
wrapTool(tool: Tool): GoogleTool {
- const inputParameters = deduplicateJsonSchemaRequiredArrays(tool.inputParameters);
+ const inputParameters = ensureObjectTypeOnProperties(
+ deduplicateJsonSchemaRequiredArrays(tool.inputParameters)
+ );
return {
name: tool.slug,
diff --git a/ts/packages/providers/google/test/google.test.ts b/ts/packages/providers/google/test/google.test.ts
index acac45059..5cd0510a8 100644
--- a/ts/packages/providers/google/test/google.test.ts
+++ b/ts/packages/providers/google/test/google.test.ts
@@ -96,6 +96,31 @@ describe('GoogleProvider', () => {
expect(wrapped.parameters?.required).toEqual(['input']);
});
+
+ it('normalizes nested object schemas without treating property maps as schemas', () => {
+ const wrapped = provider.wrapTool({
+ ...mockTool,
+ inputParameters: {
+ type: 'object',
+ properties: {
+ properties: {
+ properties: { name: { type: 'string' } },
+ },
+ },
+ },
+ });
+
+ const params = wrapped.parameters as unknown as {
+ properties: Record<string, unknown>;
+ };
+ expect(params.properties).toEqual({
+ properties: {
+ type: 'object',
+ properties: { name: { type: 'string' } },
+ },
+ });
+ expect(params.properties).not.toHaveProperty('type');
+ });
});
describe('wrapTools', () => {