Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
feat(core): rename hook handlers to condition_check and prompt_injection_check
Matches ComposioHQ/platform#14090: { type: "prompt", prompt, on_match } is now { type: "condition_check", condition, action }, and prompt_injection is now prompt_injection_check with action. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Mukund committed
Oct 21, 2026 at 14:23 UTC
bff8c4a64536a249b91f4705941dd1499c20591d
7 files changed
+53
-56
.changeset/session-hooks.md
+3
-3
@@ -16,9 +16,9 @@ const session = await composio.create('user_123', {
16
name: 'No external email',
17
appliesTo: { toolkits: ['gmail'] },
18
handler: {
19
- type: 'prompt',
20
- prompt: 'Sending email to anyone outside example.org',
21
- onMatch: 'block',
19
+ type: 'condition_check',
20
+ condition: 'Sending email to anyone outside example.org',
21
+ action: 'block',
22
},
23
},
24
],
python/composio/core/models/tool_router_session.py
+14
-12
@@ -184,24 +184,24 @@ ToolRouterHookAppliesTo = t.Union[t.Literal["all"], ToolRouterHookToolkitsScope]
184
"""Which tool calls a hook runs on: ``"all"``, or only the listed toolkits."""
185
186
187
-class ToolRouterHookPromptHandler(te.TypedDict):
188
- """Blocks a call or result when it matches ``prompt``.
187
+class ToolRouterHookConditionCheckHandler(te.TypedDict):
188
+ """Blocks a call or result when it matches ``condition``.
189
190
- ``prompt`` is a plain sentence describing what to block, for example
190
+ ``condition`` is a plain sentence describing what to block, for example
191
``"Sending email to anyone outside example.org"``.
192
"""
193
194
- type: t.Literal["prompt"]
195
- prompt: str
196
- on_match: t.Literal["block"]
194
+ type: t.Literal["condition_check"]
195
+ condition: str
196
+ action: t.Literal["block"]
197
198
199
-class ToolRouterHookPromptInjectionHandler(te.TypedDict):
200
- """A pre-defined handler that blocks results with text that tries to give
199
+class ToolRouterHookPromptInjectionCheckHandler(te.TypedDict):
200
+ """A pre-defined check that blocks results with text that tries to give
201
the agent instructions."""
202
203
- type: t.Literal["prompt_injection"]
204
- on_match: t.Literal["block"]
203
+ type: t.Literal["prompt_injection_check"]
204
+ action: t.Literal["block"]
205
206
207
class ToolRouterBeforeExecuteHook(te.TypedDict):
@@ -215,7 +215,7 @@ class ToolRouterBeforeExecuteHook(te.TypedDict):
215
id: str
216
name: te.NotRequired[str]
217
applies_to: ToolRouterHookAppliesTo
218
- handler: ToolRouterHookPromptHandler
218
+ handler: ToolRouterHookConditionCheckHandler
219
220
221
class ToolRouterAfterExecuteHook(te.TypedDict):
@@ -229,7 +229,9 @@ class ToolRouterAfterExecuteHook(te.TypedDict):
229
id: str
230
name: te.NotRequired[str]
231
applies_to: ToolRouterHookAppliesTo
232
- handler: t.Union[ToolRouterHookPromptHandler, ToolRouterHookPromptInjectionHandler]
232
+ handler: t.Union[
233
+ ToolRouterHookConditionCheckHandler, ToolRouterHookPromptInjectionCheckHandler
234
+ ]
235
236
237
ToolRouterHook = t.Union[ToolRouterBeforeExecuteHook, ToolRouterAfterExecuteHook]
python/tests/test_tool_router.py
+4
-4
@@ -2832,16 +2832,16 @@ class TestSessionHooks:
2832
"name": "No external email",
2833
"applies_to": {"toolkits": ["gmail"]},
2834
"handler": {
2835
- "type": "prompt",
2836
- "prompt": "Sending email to anyone outside example.org",
2837
- "on_match": "block",
2835
+ "type": "condition_check",
2836
+ "condition": "Sending email to anyone outside example.org",
2837
+ "action": "block",
2838
},
2839
},
2840
{
2841
"type": "after_execute",
2842
"id": "block_injection",
2843
"applies_to": "all",
2844
- "handler": {"type": "prompt_injection", "on_match": "block"},
2844
+ "handler": {"type": "prompt_injection_check", "action": "block"},
2845
},
2846
]
2847
ts/packages/core/src/lib/toolRouterParams.ts
+4
-11
@@ -197,23 +197,16 @@ export type SessionHookBody = {
197
name?: string;
198
applies_to: 'all' | { toolkits: string[] };
199
handler:
200
- | { type: 'prompt'; prompt: string; on_match: 'block' }
201
- | { type: 'prompt_injection'; on_match: 'block' };
200
+ | { type: 'condition_check'; condition: string; action: 'block' }
201
+ | { type: 'prompt_injection_check'; action: 'block' };
202
};
203
204
/** Request body of `sessions.create()`: the generated `SessionCreateParams` plus `hooks`. */
205
export type SessionCreateBody = SessionCreateParams & { hooks?: SessionHookBody[] };
206
207
-/** `hooks` as sent on create and update: `appliesTo` and `onMatch` become `applies_to` and `on_match`. */
207
+/** `hooks` as sent on create and update: `appliesTo` becomes `applies_to`. */
208
export const transformToolRouterHooksParams = (hooks: ToolRouterHook[]): SessionHookBody[] =>
209
- hooks.map(({ appliesTo, handler, ...hook }) => ({
210
- ...hook,
211
- applies_to: appliesTo,
212
- handler:
213
- handler.type === 'prompt'
214
- ? { type: 'prompt', prompt: handler.prompt, on_match: handler.onMatch }
215
- : { type: 'prompt_injection', on_match: handler.onMatch },
216
- }));
209
+ hooks.map(({ appliesTo, ...hook }) => ({ ...hook, applies_to: appliesTo }));
210
211
/**
212
* Request body of `session.update()`. Extends the generated `SessionPatchParams`
ts/packages/core/src/types/toolRouter.types.ts
+17
-15
@@ -336,29 +336,31 @@ export const ToolRouterHookAppliesToSchema = z.union([
336
]);
337
export type ToolRouterHookAppliesTo = z.infer<typeof ToolRouterHookAppliesToSchema>;
338
339
-/** Blocks a call or result when it matches `prompt`, a plain sentence describing what to block. */
340
-export const ToolRouterHookPromptHandlerSchema = z
339
+/** Blocks a call or result when it matches `condition`, a plain sentence describing what to block. */
340
+export const ToolRouterHookConditionCheckHandlerSchema = z
341
.object({
342
- type: z.literal('prompt'),
343
- prompt: z
342
+ type: z.literal('condition_check'),
343
+ condition: z
344
.string()
345
.describe(
346
'What to block, written as a plain sentence. For example: "Sending email to anyone outside example.org".'
347
),
348
- onMatch: z.literal('block'),
348
+ action: z.literal('block'),
349
})
350
.strict();
351
-export type ToolRouterHookPromptHandler = z.infer<typeof ToolRouterHookPromptHandlerSchema>;
351
+export type ToolRouterHookConditionCheckHandler = z.infer<
352
+ typeof ToolRouterHookConditionCheckHandlerSchema
353
+>;
354
353
-/** A pre-defined handler that blocks results with text that tries to give the agent instructions. */
354
-export const ToolRouterHookPromptInjectionHandlerSchema = z
355
+/** A pre-defined check that blocks results with text that tries to give the agent instructions. */
356
+export const ToolRouterHookPromptInjectionCheckHandlerSchema = z
357
.object({
356
- type: z.literal('prompt_injection'),
357
- onMatch: z.literal('block'),
358
+ type: z.literal('prompt_injection_check'),
359
+ action: z.literal('block'),
360
})
361
.strict();
360
-export type ToolRouterHookPromptInjectionHandler = z.infer<
361
- typeof ToolRouterHookPromptInjectionHandlerSchema
362
+export type ToolRouterHookPromptInjectionCheckHandler = z.infer<
363
+ typeof ToolRouterHookPromptInjectionCheckHandlerSchema
364
>;
365
366
const toolRouterHookIdentityFields = {
@@ -380,7 +382,7 @@ export const ToolRouterHookSchema = z.discriminatedUnion('type', [
382
.object({
383
type: z.literal('before_execute'),
384
...toolRouterHookIdentityFields,
383
- handler: ToolRouterHookPromptHandlerSchema,
385
+ handler: ToolRouterHookConditionCheckHandlerSchema,
386
})
387
.strict(),
388
z
@@ -388,8 +390,8 @@ export const ToolRouterHookSchema = z.discriminatedUnion('type', [
390
type: z.literal('after_execute'),
391
...toolRouterHookIdentityFields,
392
handler: z.discriminatedUnion('type', [
391
- ToolRouterHookPromptHandlerSchema,
392
- ToolRouterHookPromptInjectionHandlerSchema,
393
+ ToolRouterHookConditionCheckHandlerSchema,
394
+ ToolRouterHookPromptInjectionCheckHandlerSchema,
395
]),
396
})
397
.strict(),
ts/packages/core/test/lib/toolRouterParams.test.ts
+8
-8
@@ -236,16 +236,16 @@ describe('transformToolRouterUpdateParams', () => {
236
name: 'No external email',
237
appliesTo: { toolkits: ['gmail'] },
238
handler: {
239
- type: 'prompt',
240
- prompt: 'Sending email to anyone outside example.org',
241
- onMatch: 'block',
239
+ type: 'condition_check',
240
+ condition: 'Sending email to anyone outside example.org',
241
+ action: 'block',
242
},
243
},
244
{
245
type: 'after_execute',
246
id: 'block_injection',
247
appliesTo: 'all',
248
- handler: { type: 'prompt_injection', onMatch: 'block' },
248
+ handler: { type: 'prompt_injection_check', action: 'block' },
249
},
250
],
251
})
@@ -257,16 +257,16 @@ describe('transformToolRouterUpdateParams', () => {
257
name: 'No external email',
258
applies_to: { toolkits: ['gmail'] },
259
handler: {
260
- type: 'prompt',
261
- prompt: 'Sending email to anyone outside example.org',
262
- on_match: 'block',
260
+ type: 'condition_check',
261
+ condition: 'Sending email to anyone outside example.org',
262
+ action: 'block',
263
},
264
},
265
{
266
type: 'after_execute',
267
id: 'block_injection',
268
applies_to: 'all',
269
- handler: { type: 'prompt_injection', on_match: 'block' },
269
+ handler: { type: 'prompt_injection_check', action: 'block' },
270
},
271
],
272
});
ts/packages/core/test/models/toolRouter.test.ts
+3
-3
@@ -248,7 +248,7 @@ describe('ToolRouter', () => {
248
type: 'after_execute',
249
id: 'block_injection',
250
appliesTo: 'all',
251
- handler: { type: 'prompt_injection', onMatch: 'block' },
251
+ handler: { type: 'prompt_injection_check', action: 'block' },
252
},
253
],
254
});
@@ -261,7 +261,7 @@ describe('ToolRouter', () => {
261
type: 'after_execute',
262
id: 'block_injection',
263
applies_to: 'all',
264
- handler: { type: 'prompt_injection', on_match: 'block' },
264
+ handler: { type: 'prompt_injection_check', action: 'block' },
265
},
266
],
267
});
@@ -279,7 +279,7 @@ describe('ToolRouter', () => {
279
type: 'after_execute',
280
id: 'block_injection',
281
appliesTo: 'all',
282
- handler: { type: 'prompt_injection', onMatch: 'block' },
282
+ handler: { type: 'prompt_injection_check', action: 'block' },
283
},
284
],
285
experimental: { sessionConfigId: 'sc_1' },