Schema Modifiers

Learn how to use schema modifiers to transform tool schemas before they are seen by agents.

Schema modifiers are part of Composio SDK’s powerful middleware capabilities that allow you to customize and extend the behavior of tools.

Schema Modifiers

Schema modifiers transform a tool’s schema before the tool is seen by an agent.

Schema Modifier

Useful for: - Adding arguments to the tool. For example, adding a thought argument to the tool to prompt the agent to explain the reasoning. - Hiding arguments from the tool. In cases where the argument is irrelevant to the tool. - Adding extra arguments to the tool schema for custom use cases or execution. - Adding default values to tool arguments.

Below we modify the schema of the HACKERNEWS_GET_LATEST_POSTS to make the size argument required and remove the page argument.

1const userId = "your@email.com";
2
3const tools = await composio.tools.get(
4 userId,
5 {
6 tools: ["HACKERNEWS_GET_LATEST_POSTS", "HACKERNEWS_GET_USER"],
7 },
8 {
9 modifyToolSchema: (toolSlug, _, toolSchema) => {
10 if (toolSlug === "HACKERNEWS_GET_LATEST_POSTS") {
11 const { inputParameters } = toolSchema;
12 if (inputParameters?.properties) {
13 delete inputParameters.properties["page"];
14 }
15 inputParameters.required = ["size"];
16 }
17 return toolSchema;
18 },
19 }
20);
21
22console.log(JSON.stringify(tools, null, 2));

In using the above modified tool schema, the page argument is removed and the size argument is required.

You can test this out by viewing the tool call response in the LLM too!

1import { Composio } from '@composio/core';
2import { OpenAI } from 'openai';
3
4const composio = new Composio({
5 apiKey: process.env.COMPOSIO_API_KEY,
6});
7const openai = new OpenAI();
8
9const userId = 'your@email.com';
10
11const tools = await composio.tools.get(
12 userId,
13 {
14 tools: ['HACKERNEWS_GET_LATEST_POSTS', 'HACKERNEWS_GET_USER'],
15 },
16 {
17 modifyToolSchema: (toolSlug, _, toolSchema) => {
18 if (toolSlug === 'HACKERNEWS_GET_LATEST_POSTS') {
19 const { inputParameters } = toolSchema;
20 if (inputParameters?.properties) {
21 delete inputParameters.properties['page'];
22 }
23 inputParameters.required = ['size'];
24 }
25 return toolSchema;
26 },
27 }
28);
29
30console.log(JSON.stringify(tools, null, 2));
31
32const response = await openai.chat.completions.create({
33 model: 'gpt-4o-mini',
34 messages: [
35 {
36 role: 'system',
37 content: 'You are a helpful assistant that can help with tasks.',
38 },
39 { role: 'user', content: 'Get the latest posts from Hacker News' },
40 ],
41 tools: tools,
42 tool_choice: 'auto',
43});
44
45console.log(response.choices[0].message.tool_calls);