https://linen.dev logo
Managing tools context
# 🖥│support-forum
m
most tools returns too long responses which leads to over context from llm provider (too long context) **my question**: does composio provide a way to handle this automatically, and incase not how to get expected infer type of tool response so we can handle this from our side! code example
Copy code
ts
const { data } = await composio.tools.execute('GMAIL_FETCH_EMAILS', {})
const dataResponse = data // typeof data => Record<string, unknown>  ??
@composiohq đź‘€
u
Hey @mustafaskyer, If you are trying to modify the tool response before passing it to the LLM, yes, you can use AfterExecution: https://docs.composio.dev/docs/modifying-tool-outputs — Let me know if you need any help.
m
Hi @Uday thanks for the reply, **but also using afterExecution, I don't know what's inside the data, therfor can't loop over and find useless long content to ignore ** https://cdn.discordapp.com/attachments/1433859499177021552/1434095838279368845/Screenshot_2025-11-01_at_11.22.24_AM.png?ex=69071554&is=6905c3d4&hm=361b9c798bfd5ae8741afdbea2beb076c632d02edbd726e3f8476e04d46f3d6e&
a
I understand your concern! To know what's inside the
data
object for a specific tool, you need to inspect the tool's output schema. Composio provides several ways to do this: ### 1. Get the Raw Tool Schema You can fetch the raw tool definition to see the exact output parameters:
Copy code
typescript
// Get the raw tool schema
const tool = await composio.tools.getRawComposioToolBySlug('GMAIL_FETCH_EMAILS');

// Inspect the output parameters
console.log(tool.output_parameters);
This will show you the complete structure of what the tool returns, including all fields and their types [[getRawComposioToolBySlug]](https://docs.composio.dev/sdk-reference/type-script/models/tools#getrawcomposiotoolbyslug). ### 2. Check the Tool Documentation You can also view the tool's schema in the Composio documentation. For example, the [Tool Type Generator documentation](https://docs.composio.dev/examples/tool-generator#getting-the-raw-tool-definition) shows how tool schemas include detailed
output_parameters
with properties like:
Copy code
json
{
  "output_parameters": {
    "properties": {
      "data": {
        "description": "Data from the action execution",
        "properties": {
          "response_data": {
            "description": "Full response with details",
            "type": "object"
          }
        }
      }
    }
  }
}
### 3. Practical Approach Once you know the schema, you can create a targeted
afterExecute
modifier:
Copy code
typescript
// First, inspect the schema
const tool = await composio.tools.getRawComposioToolBySlug('GMAIL_FETCH_EMAILS');
console.log(JSON.stringify(tool.output_parameters, null, 2));

// Then create your modifier based on what you see
const result = await composio.tools.execute(
  'GMAIL_FETCH_EMAILS',
  {
    userId,
    arguments: { /* your arguments */ },
  },
  {
    afterExecute: ({ toolSlug, toolkitSlug, result }) => {
      if (result.successful && result.data) {
        // Based on the schema, keep only essential fields
        // For example, if emails is an array with many fields:
        const trimmedData = {
          emails: (result.data.emails as any[] || []).map(email => ({
            id: email.id,
            subject: email.subject,
            from: email.from,
            // Add only the fields you need
          }))
        };
        return {
          ...result,
          data: trimmedData,
        };
      }
      return result;
    },
  }
);
This way, you can inspect the schema first to understand what fields are available, then create a modifier that keeps only what you need [[Fetching raw tools]](https://github.com/composioHQ/composio/blob/next/fern/pages/src/tool-calling/fetching-tools.mdx).
m
Just to confirm With this approach I've to send a request for each tool I want to execute to get output params, also will need to use a schema convert like
json to zod
If so just confirm, and I think this shouldn't be the way to just get a return type of an execution !!
j
Would love to hear if there's a resolution to this, seems like a common issue with tools that can query large data sets
a
I think tool router will be a really great fit for such a use case. Here we have a remote workbench tool where we handle all the nuances of handling these large datasets. Do check it out.
Would love to get you both on a call to understand the pain points and help you integrate toolrouter or any answer any questions you have on it. .
m
Hi Sushmitha, Thanks for your reply, let me experiment with tool router first, then we can have call!