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(typesafe): guard required arguments in compilation and execution
shams haroon committed
Sep 17, 2026 at 20:23 UTC
cf15b62e6082a53f7b71570b8fc6c83b3c4e2b47
8 files changed
+138
-7
python/providers/typesafe/README.md
+1
@@ -244,6 +244,7 @@ Check how [TypeSafe](https://docs.typesafe.ai) retains request data before you s
244
- A tool set holds at most 254 tools. More raises `TypesafeLimitError`.
245
- A state that exceeds the request budget raises `TypesafeLimitError`. The provider never truncates state.
246
- Closed-set properties nested inside object arguments are open-ended.
247
+- Root-level `allOf`, `anyOf`, and `oneOf` raise `TypesafeInvalidOptionsError` when wrapping a tool. Use a flat object schema with top-level `properties` and `required`; requirements inside root composition are not supported.
248
- `execute` takes a user ID with modifiers, or a session. It has no `connected_account_id` option yet.
249
250
## Links
python/providers/typesafe/composio_typesafe/compile.py
+21
-3
@@ -25,6 +25,7 @@ from .types import (
25
TypesafeArrayArgument,
26
TypesafeChoiceQuestion,
27
TypesafeDuplicateToolError,
28
+ TypesafeInvalidOptionsError,
29
TypesafeNoulQuestion,
30
TypesafeOption,
31
TypesafeRisk,
@@ -33,12 +34,29 @@ from .types import (
34
)
35
36
37
+class _RootComposition(BaseModel):
38
+ allOf: t.Any = None
39
+ anyOf: t.Any = None
40
+ oneOf: t.Any = None
41
+
42
+
43
class _InputParameters(BaseModel):
44
properties: t.Dict[StrictStr, t.Any] = {}
45
required: t.List[StrictStr] = []
46
47
41
-def _parse_input_parameters(schema: t.Any) -> _InputParameters:
48
+def _parse_input_parameters(schema: t.Any, tool_slug: str) -> _InputParameters:
49
+ try:
50
+ composition = _RootComposition.model_validate(schema)
51
+ except PydanticValidationError:
52
+ return _InputParameters()
53
+ # Root composition can add required arguments the flat-object compiler cannot see.
54
+ for keyword in ("allOf", "anyOf", "oneOf"):
55
+ if keyword in composition.model_fields_set:
56
+ raise TypesafeInvalidOptionsError(
57
+ f'Tool "{tool_slug}" uses unsupported root schema keyword "{keyword}". '
58
+ "Use a flat object schema with top-level properties and required."
59
+ )
60
try:
61
return _InputParameters.model_validate(schema)
62
except PydanticValidationError:
@@ -196,12 +214,12 @@ def routing_description_of(tool: Tool) -> str:
214
215
216
def compile_tool(tool: Tool) -> TypesafeToolQuestions:
199
- """Compiles one tool. What it cannot read in a schema is open-ended."""
217
+ """Compiles one tool. Unsupported properties are open-ended; root composition raises."""
218
dereferenced = dereference_json_schema(
219
getattr(tool, "input_parameters", None) or {"type": "object", "properties": {}},
220
on_unresolved="sentinel",
221
)
204
- parsed = _parse_input_parameters(dereferenced)
222
+ parsed = _parse_input_parameters(dereferenced, tool.slug)
223
names = sorted(parsed.properties, key=by_code_unit)
224
# `required` is a set, and a name with no matching property is ignored.
225
required_set = set(parsed.required)
python/tests/test_typesafe_provider.py
+42
@@ -284,6 +284,48 @@ LIST_SYMBOLS = corpus_tool("no_input_parameters")
284
285
286
class TestQuestionCorpus:
287
+ @pytest.mark.parametrize("keyword", ["allOf", "anyOf", "oneOf"])
288
+ def test_rejects_root_composition_with_required_arguments(
289
+ self, keyword: str
290
+ ) -> None:
291
+ tool = make_tool(
292
+ "COMPOSED",
293
+ inputParameters={
294
+ "type": "object",
295
+ keyword: [
296
+ {"properties": {"title": {"type": "string"}}, "required": ["title"]}
297
+ ],
298
+ },
299
+ )
300
+ with pytest.raises(TypesafeInvalidOptionsError) as error:
301
+ TypesafeProvider().wrap_tools([tool])
302
+ assert str(error.value) == (
303
+ f'Tool "COMPOSED" uses unsupported root schema keyword "{keyword}". '
304
+ "Use a flat object schema with top-level properties and required."
305
+ )
306
+
307
+ def test_rejects_root_composition_through_schema_reference(self) -> None:
308
+ tool = make_tool(
309
+ "REFERENCED",
310
+ inputParameters={
311
+ "type": "object",
312
+ "$ref": "#/$defs/input",
313
+ "$defs": {
314
+ "input": {
315
+ "type": "object",
316
+ "allOf": [
317
+ {
318
+ "properties": {"title": {"type": "string"}},
319
+ "required": ["title"],
320
+ }
321
+ ],
322
+ }
323
+ },
324
+ },
325
+ )
326
+ with pytest.raises(TypesafeInvalidOptionsError):
327
+ TypesafeProvider().wrap_tool(tool)
328
+
329
@pytest.mark.parametrize(
330
"entry", CORPUS["tools"], ids=[entry["name"] for entry in CORPUS["tools"]]
331
)
ts/packages/providers/typesafe/README.md
+1
@@ -219,6 +219,7 @@ Check how [TypeSafe](https://docs.typesafe.ai) retains request data before you s
219
- A state that exceeds the request budget throws `TypesafeLimitError`. The provider never truncates state.
220
- A state object with a top-level key other than `request` and `context`, or with a value that is not JSON, throws `TypesafeInvalidOptionsError`.
221
- Closed-set properties nested inside object arguments are open-ended.
222
+- Root-level `allOf`, `anyOf`, and `oneOf` throw `TypesafeInvalidOptionsError` when wrapping a tool. Use a flat object schema with top-level `properties` and `required`; requirements inside root composition are not supported.
223
224
## Links
225
ts/packages/providers/typesafe/src/compile.ts
+19
-1
@@ -9,6 +9,7 @@ import { classifyProperty } from './classify';
9
import { buildOptions, NONE_KEY, NOT_STATED_KEY, NULL_KEY, optionKey, optionLabel } from './keys';
10
import {
11
TypesafeDuplicateToolError,
12
+ TypesafeInvalidOptionsError,
13
type TypesafeArgumentQuestion,
14
type TypesafeChoiceQuestion,
15
type TypesafeNoulQuestion,
@@ -18,6 +19,12 @@ import {
19
type TypesafeToolSet,
20
} from './types';
21
22
+const RootCompositionSchema = z.object({
23
+ allOf: z.unknown().optional(),
24
+ anyOf: z.unknown().optional(),
25
+ oneOf: z.unknown().optional(),
26
+});
27
+
28
const InputParametersSchema = z.object({
29
properties: z.record(z.string(), z.unknown()).optional(),
30
required: z.array(z.string()).optional(),
@@ -144,12 +151,23 @@ function compileArgument(
151
export const routingDescriptionOf = (tool: Tool): string =>
152
tool.description ? `${tool.name}: ${tool.description}` : tool.name;
153
147
-/** Compiles one tool. Never throws on a schema: what it cannot read is open-ended. */
154
+/** Compiles one tool. Unsupported properties are open-ended; root composition is rejected. */
155
export function compileTool(tool: Tool): TypesafeToolQuestions {
156
const dereferenced: unknown = dereferenceJsonSchema(
157
tool.inputParameters ?? { type: 'object', properties: {} },
158
{ onUnresolved: 'sentinel' }
159
);
160
+ // Root composition can add required arguments that the flat-object compiler cannot see.
161
+ const composition = RootCompositionSchema.safeParse(dereferenced);
162
+ if (composition.success) {
163
+ const keyword = Object.keys(composition.data)[0];
164
+ if (keyword !== undefined) {
165
+ throw new TypesafeInvalidOptionsError(
166
+ `Tool "${tool.slug}" uses unsupported root schema keyword "${keyword}". ` +
167
+ 'Use a flat object schema with top-level properties and required.'
168
+ );
169
+ }
170
+ }
171
const parsed = InputParametersSchema.safeParse(dereferenced);
172
const properties = parsed.success ? (parsed.data.properties ?? {}) : {};
173
const names = Object.keys(properties).sort(byCodeUnit);
ts/packages/providers/typesafe/src/index.ts
+2
-2
@@ -147,13 +147,13 @@ export class TypesafeProvider extends BaseNonAgenticProvider<
147
if (parsed.data.kind === 'abstain') throw new TypesafeAbstainedDecisionError();
148
this.assertToolCallExecutionOptions(executionTarget, options, modifiers);
149
150
- // Caller arguments win over Jev-bound values. Only `undefined` counts as missing.
150
+ // Caller arguments win over Jev-bound values. Absent or undefined values are missing.
151
const callArguments = { ...parsed.data.arguments };
152
for (const [name, value] of Object.entries(input?.arguments ?? {})) {
153
if (value !== undefined) callArguments[name] = value;
154
}
155
const missing = (parsed.data.kind === 'partial' ? parsed.data.missing : []).filter(
156
- path => callArguments[path[0]] === undefined
156
+ path => !Object.hasOwn(callArguments, path[0]) || callArguments[path[0]] === undefined
157
);
158
if (missing.length > 0) throw new TypesafeIncompleteDecisionError(missing);
159
ts/packages/providers/typesafe/test/compile.test.ts
+33
-1
@@ -1,6 +1,7 @@
1
+import type { JSONSchemaProperty } from '@composio/core';
2
import fc from 'fast-check';
3
import { describe, expect, it } from 'vitest';
3
-import { TypesafeDuplicateToolError, TypesafeProvider } from '../src';
4
+import { TypesafeDuplicateToolError, TypesafeInvalidOptionsError, TypesafeProvider } from '../src';
5
import { routingQuestion } from '../src/compile';
6
import { buildOptions, optionValues } from '../src/keys';
7
import { corpus, makeTool } from './helpers';
@@ -30,6 +31,37 @@ describe('question corpus', () => {
31
});
32
33
describe('wrapTools', () => {
34
+ it.each(['allOf', 'anyOf', 'oneOf'])(
35
+ 'rejects root %s instead of silently dropping required arguments',
36
+ keyword => {
37
+ const tool = makeTool('COMPOSED', {}, [], {
38
+ inputParameters: {
39
+ type: 'object',
40
+ [keyword]: [{ properties: { title: { type: 'string' } }, required: ['title'] }],
41
+ },
42
+ });
43
+ expect(() => provider.wrapTools([tool])).toThrow(TypesafeInvalidOptionsError);
44
+ expect(() => provider.wrapTools([tool])).toThrow(
45
+ `Tool "COMPOSED" uses unsupported root schema keyword "${keyword}".`
46
+ );
47
+ }
48
+ );
49
+
50
+ it('rejects root composition reached through a schema reference', () => {
51
+ const inputParameters = {
52
+ type: 'object',
53
+ $ref: '#/$defs/input',
54
+ $defs: {
55
+ input: {
56
+ type: 'object',
57
+ allOf: [{ properties: { title: { type: 'string' } }, required: ['title'] }],
58
+ },
59
+ },
60
+ } satisfies JSONSchemaProperty;
61
+ const tool = makeTool('REFERENCED', {}, [], { inputParameters });
62
+ expect(() => provider.wrapTool(tool)).toThrow(TypesafeInvalidOptionsError);
63
+ });
64
+
65
it('returns an empty tool set for no tools and throws on duplicate slugs', () => {
66
expect(provider.wrapTools([])).toEqual({ tools: [] });
67
expect(() => provider.wrapTools([makeTool('SAME'), makeTool('SAME')])).toThrow(
ts/packages/providers/typesafe/test/execute.test.ts
+19
@@ -103,6 +103,25 @@ describe('execute', () => {
103
);
104
});
105
106
+ it.each(['toString', 'constructor'])(
107
+ 'requires an explicitly supplied value for the argument %s',
108
+ async name => {
109
+ const decision: TypesafePartialDecision = { ...partial, missing: [[name]] };
110
+ await expect(provider.execute('user_1', decision)).rejects.toMatchObject({
111
+ name: 'TypesafeIncompleteDecisionError',
112
+ missing: [[name]],
113
+ });
114
+ expect(executeTool).not.toHaveBeenCalled();
115
+
116
+ await provider.execute('user_1', decision, { arguments: { [name]: 'supplied' } });
117
+ expect(executeTool).toHaveBeenCalledExactlyOnceWith(
118
+ 'ISSUES_CREATE',
119
+ expect.objectContaining({ arguments: { priority: 'low', [name]: 'supplied' } }),
120
+ undefined
121
+ );
122
+ }
123
+ );
124
+
125
it('executes through a session, which takes no modifiers', async () => {
126
const session = {
127
execute: vi.fn().mockResolvedValue({ data: { ok: true }, error: null, logId: 'log_1' }),