@devries-cameron20 / composio-1 / commits / a2f6b9699
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(json-schema): integrate Google object type normalization

Co-authored-by: jkomyno <alberto@composio.dev>

sergioperezcheco committed Aug 10, 2026 at 21:51 UTC a2f6b9699b753d6a1e20c6e3f996b71a32181b56
9 files changed +311 -2
.changeset/ensure-object-type-on-properties.md new
+5
@@ -0,0 +1,5 @@
1 +---
2 +'@composio/core': patch
3 +---
4 +
5 +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.
.changeset/normalize-google-object-types.md new
+5
@@ -0,0 +1,5 @@
1 +---
2 +'@composio/google': patch
3 +---
4 +
5 +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.
docs/content/changelog/08-06-26-free-form-tool-arguments.mdx
+5
@@ -13,6 +13,7 @@ date: '2026-08-06'
13 | TypeScript `@composio/slim` | `0.16.0` |
14 | TypeScript `@composio/json-schema-to-zod` | `0.3.0` |
15 | TypeScript `@composio/claude-agent-sdk` | `0.11.0` |
16 +| TypeScript `@composio/google` | `0.10.2` |
17
18 ---
19
@@ -22,6 +23,10 @@ A tool argument declared as a bare `{"type": "object"}` — with no `properties`
23
24 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.
25
26 +#### Google Gemini schema compatibility
27 +
28 +`@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`.
29 +
30 **Before:**
31
32 ```python
ts/packages/core/src/index.ts
+1
@@ -7,6 +7,7 @@ export type { BaseComposioProvider } from './provider/BaseProvider';
7 export {
8 dereferenceJsonSchema,
9 deduplicateJsonSchemaRequiredArrays,
10 + ensureObjectTypeOnProperties,
11 jsonSchemaToZodSchema,
12 removeNonRequiredProperties,
13 } from './utils/jsonSchema';
ts/packages/core/src/utils/jsonSchema.ts
+85
@@ -258,6 +258,91 @@ export function dereferenceJsonSchema<T = unknown>(
258 return out as T;
259 }
260
261 +/**
262 + * Returns a deep-cloned JSON Schema in which every node that carries a
263 + * `properties` keyword also carries `type: "object"` when it has no explicit
264 + * `type`. OpenAI tolerates the omission, but Google Gemini enforces OpenAPI
265 + * 3.0 strictly and rejects function declarations whose nested objects are
266 + * missing the `type` (see https://github.com/ComposioHQ/composio/issues/4022).
267 + *
268 + * The function follows JSON Schema's schema-bearing keywords while keeping
269 + * property maps and instance values as containers. Nodes that already declare
270 + * a `type` are left untouched.
271 + */
272 +export function ensureObjectTypeOnProperties<T = unknown>(schema: T): T {
273 + type WalkMode = 'schema' | 'schema-array' | 'schema-map' | 'dependencies-map' | 'value';
274 +
275 + const schemaKeywords = new Set([
276 + 'additionalItems',
277 + 'additionalProperties',
278 + 'contains',
279 + 'contentSchema',
280 + 'else',
281 + 'if',
282 + 'not',
283 + 'propertyNames',
284 + 'then',
285 + 'unevaluatedItems',
286 + 'unevaluatedProperties',
287 + ]);
288 + const schemaArrayKeywords = new Set(['allOf', 'anyOf', 'oneOf', 'prefixItems']);
289 + const schemaMapKeywords = new Set([
290 + '$defs',
291 + 'definitions',
292 + 'dependentSchemas',
293 + 'patternProperties',
294 + 'properties',
295 + ]);
296 +
297 + function walk(value: unknown, mode: WalkMode, depth = 0): unknown {
298 + if (depth > MAX_NODE_DEPTH) {
299 + throw new RangeError(`JSON Schema exceeds maximum nesting depth of ${MAX_NODE_DEPTH}`);
300 + }
301 +
302 + if (Array.isArray(value)) {
303 + const itemMode = mode === 'schema-array' ? 'schema' : 'value';
304 + return value.map(item => walk(item, itemMode, depth + 1));
305 + }
306 +
307 + if (!isPlainObject(value)) return value;
308 +
309 + const clone: Record<string, unknown> = {};
310 + for (const [key, child] of Object.entries(value)) {
311 + let childMode: WalkMode = 'value';
312 + if (mode === 'schema-map') {
313 + childMode = 'schema';
314 + } else if (mode === 'dependencies-map') {
315 + childMode = Array.isArray(child) ? 'value' : 'schema';
316 + } else if (mode === 'schema') {
317 + if (schemaMapKeywords.has(key)) {
318 + childMode = 'schema-map';
319 + } else if (schemaArrayKeywords.has(key) || (key === 'items' && Array.isArray(child))) {
320 + childMode = 'schema-array';
321 + } else if (schemaKeywords.has(key) || key === 'items') {
322 + childMode = 'schema';
323 + } else if (key === 'dependencies') {
324 + childMode = 'dependencies-map';
325 + }
326 + }
327 +
328 + Object.defineProperty(clone, key, {
329 + configurable: true,
330 + enumerable: true,
331 + value: walk(child, childMode, depth + 1),
332 + writable: true,
333 + });
334 + }
335 +
336 + if (mode === 'schema' && clone.properties !== undefined && clone.type === undefined) {
337 + clone.type = 'object';
338 + }
339 +
340 + return clone;
341 + }
342 +
343 + return walk(schema, 'schema') as T;
344 +}
345 +
346 /**
347 * Returns a deep-cloned JSON Schema whose `required` arrays contain each entry
348 * at most once. Duplicate entries are invalid in JSON Schema 2020-12 but do
ts/packages/core/test/utils/jsonSchema.test.ts
+180
@@ -2,6 +2,7 @@ import { describe, it, expect, vi } from 'vitest';
2 import {
3 deduplicateJsonSchemaRequiredArrays,
4 dereferenceJsonSchema,
5 + ensureObjectTypeOnProperties,
6 } from '../../src/utils/jsonSchema';
7 import { JsonSchemaRefResolutionError } from '../../src/errors/ValidationErrors';
8 import logger from '../../src/utils/logger';
@@ -686,3 +687,182 @@ describe('shared corpus invariants', () => {
687 expect(() => assertCorpusInvariants([declared])).not.toThrow();
688 });
689 });
690 +
691 +describe('ensureObjectTypeOnProperties', () => {
692 + it('adds type:object to nested nodes that have properties but no type', () => {
693 + const schema = {
694 + type: 'object',
695 + properties: {
696 + target: {
697 + properties: {
698 + name: { type: 'string' },
699 + },
700 + },
701 + },
702 + };
703 +
704 + const result = ensureObjectTypeOnProperties(schema);
705 + expect(result).toEqual({
706 + type: 'object',
707 + properties: {
708 + target: {
709 + type: 'object',
710 + properties: {
711 + name: { type: 'string' },
712 + },
713 + },
714 + },
715 + });
716 + });
717 +
718 + it('leaves nodes that already declare a type untouched', () => {
719 + const schema = {
720 + type: 'object',
721 + properties: {
722 + target: {
723 + type: 'object',
724 + properties: { name: { type: 'string' } },
725 + },
726 + },
727 + };
728 +
729 + const result = ensureObjectTypeOnProperties(schema);
730 + expect(result).toEqual(schema);
731 + });
732 +
733 + it('handles deeply nested properties inside array items', () => {
734 + const schema = {
735 + type: 'object',
736 + properties: {
737 + list: {
738 + type: 'array',
739 + items: {
740 + properties: { id: { type: 'string' } },
741 + },
742 + },
743 + },
744 + };
745 +
746 + const result = ensureObjectTypeOnProperties(schema) as typeof schema;
747 + expect(result.properties.list.items).toHaveProperty('type', 'object');
748 + });
749 +
750 + it('does not mutate the input schema', () => {
751 + const schema = {
752 + type: 'object',
753 + properties: {
754 + target: { properties: { name: { type: 'string' } } },
755 + },
756 + };
757 +
758 + ensureObjectTypeOnProperties(schema);
759 + expect(schema.properties.target).not.toHaveProperty('type');
760 + });
761 +
762 + it('does not inject type:object into instance-value keywords (const, default, enum, examples)', () => {
763 + const schema = {
764 + type: 'object',
765 + properties: {
766 + choice: {
767 + type: 'object',
768 + properties: { id: { type: 'string' } },
769 + default: { properties: { should_not_gain_type: true } },
770 + const: { properties: { marker: true } },
771 + examples: [{ properties: { marker: true } }],
772 + enum: [{ properties: { marker: true } }],
773 + },
774 + },
775 + };
776 +
777 + const result = ensureObjectTypeOnProperties(schema) as typeof schema;
778 + const choice = result.properties.choice as Record<string, unknown>;
779 + expect((choice.default as Record<string, unknown>).type).toBeUndefined();
780 + expect((choice.const as Record<string, unknown>).type).toBeUndefined();
781 + expect((choice.examples as Record<string, unknown>[])[0].type).toBeUndefined();
782 + expect((choice.enum as Record<string, unknown>[])[0].type).toBeUndefined();
783 + });
784 +
785 + it('does not treat a properties map as a schema when a field is named properties', () => {
786 + const schema = {
787 + type: 'object',
788 + properties: {
789 + properties: {
790 + properties: {
791 + name: { type: 'string' },
792 + },
793 + },
794 + },
795 + };
796 +
797 + const result = ensureObjectTypeOnProperties(schema) as {
798 + properties: Record<string, unknown>;
799 + };
800 +
801 + expect(result.properties).toEqual({
802 + properties: {
803 + type: 'object',
804 + properties: {
805 + name: { type: 'string' },
806 + },
807 + },
808 + });
809 + expect(result.properties).not.toHaveProperty('type');
810 + });
811 +
812 + it('preserves reserved property names without changing the property-map prototype', () => {
813 + const propertySchemas: Record<string, unknown> = {};
814 + for (const key of ['constructor', 'prototype', '__proto__']) {
815 + Object.defineProperty(propertySchemas, key, {
816 + configurable: true,
817 + enumerable: true,
818 + value: { properties: { value: { type: 'string' } } },
819 + writable: true,
820 + });
821 + }
822 +
823 + const result = ensureObjectTypeOnProperties({
824 + type: 'object',
825 + properties: propertySchemas,
826 + });
827 +
828 + expect(Object.getPrototypeOf(result.properties)).toBe(Object.prototype);
829 + for (const key of ['constructor', 'prototype', '__proto__']) {
830 + expect(Object.hasOwn(result.properties, key)).toBe(true);
831 + expect(result.properties[key]).toEqual({
832 + type: 'object',
833 + properties: { value: { type: 'string' } },
834 + });
835 + }
836 + });
837 +
838 + it('preserves reserved keys in instance defaults without treating their values as schemas', () => {
839 + const defaultValue: Record<string, unknown> = {};
840 + for (const key of ['constructor', 'prototype', '__proto__']) {
841 + Object.defineProperty(defaultValue, key, {
842 + configurable: true,
843 + enumerable: true,
844 + value: { properties: { marker: true } },
845 + writable: true,
846 + });
847 + }
848 +
849 + const result = ensureObjectTypeOnProperties({
850 + type: 'object',
851 + properties: {
852 + choice: {
853 + type: 'object',
854 + properties: {},
855 + default: defaultValue,
856 + },
857 + },
858 + });
859 + const normalizedDefault = result.properties.choice.default;
860 +
861 + expect(Object.getPrototypeOf(normalizedDefault)).toBe(Object.prototype);
862 + for (const key of ['constructor', 'prototype', '__proto__']) {
863 + expect(Object.hasOwn(normalizedDefault, key)).toBe(true);
864 + expect(normalizedDefault[key]).toEqual({ properties: { marker: true } });
865 + expect(normalizedDefault[key]).not.toHaveProperty('type');
866 + }
867 + });
868 +});
ts/packages/providers/google/package.json
+1 -1
@@ -43,7 +43,7 @@
43 "author": "",
44 "license": "ISC",
45 "peerDependencies": {
46 - "@composio/core": ">=0.10.0 <1.0.0",
46 + "@composio/core": ">=0.16.0 <1.0.0",
47 "@google/genai": "^1.1.0"
48 },
49 "devDependencies": {
ts/packages/providers/google/src/index.ts
+4 -1
@@ -17,6 +17,7 @@ import {
17 McpServerGetResponse,
18 normalizeToolArguments,
19 deduplicateJsonSchemaRequiredArrays,
20 + ensureObjectTypeOnProperties,
21 } from '@composio/core';
22 import { FunctionDeclaration, Schema } from '@google/genai';
23
@@ -128,7 +129,9 @@ export class GoogleProvider extends BaseNonAgenticProvider<
129 * ```
130 */
131 wrapTool(tool: Tool): GoogleTool {
131 - const inputParameters = deduplicateJsonSchemaRequiredArrays(tool.inputParameters);
132 + const inputParameters = ensureObjectTypeOnProperties(
133 + deduplicateJsonSchemaRequiredArrays(tool.inputParameters)
134 + );
135
136 return {
137 name: tool.slug,
ts/packages/providers/google/test/google.test.ts
+25
@@ -96,6 +96,31 @@ describe('GoogleProvider', () => {
96
97 expect(wrapped.parameters?.required).toEqual(['input']);
98 });
99 +
100 + it('normalizes nested object schemas without treating property maps as schemas', () => {
101 + const wrapped = provider.wrapTool({
102 + ...mockTool,
103 + inputParameters: {
104 + type: 'object',
105 + properties: {
106 + properties: {
107 + properties: { name: { type: 'string' } },
108 + },
109 + },
110 + },
111 + });
112 +
113 + const params = wrapped.parameters as unknown as {
114 + properties: Record<string, unknown>;
115 + };
116 + expect(params.properties).toEqual({
117 + properties: {
118 + type: 'object',
119 + properties: { name: { type: 'string' } },
120 + },
121 + });
122 + expect(params.properties).not.toHaveProperty('type');
123 + });
124 });
125
126 describe('wrapTools', () => {