Processing Tools
Enhancing tool reliability with schema, input, and output transformations
Schema Processing and Preprocessing
There may be scenarios where you want to control how the LLM calls a tool and how Composio executes it. You may want to remove some parameters from the schema, inject some values into the tool call or process the response from the tool call.
Let’s take GMAIL_SEND_EMAIL
as an example. Below is the schema.
GMAIL_SEND_EMAIL
Schema
GMAIL_SEND_EMAIL
SchemaThis emits a tool call to GMAIL_SEND_EMAIL
from the LLM. Here are the arguments for it.
When building a system that already infers parameters, the LLM doesn’t need to generate these parameters - you can inject them directly.
This is where tool processing comes into play.
Handler to modify the tool schema, description, parameters before sending to an LLM.
Handler to modify or inject parameters before executing a tool call.
Developers looking to improve agent reliability should analyze both the schema and outputs of tools, then use these processors to make interactions more deterministic where needed.
Schema processing
Say your system already infers the recipient_email
parameter and you don’t want to send anattachment
.
You wouldn’t want the LLM to generate it in the tool call.
You can simply modify the schema processor to do so:
This removes the recipient_email
and attachment
parameters from the schema, preventing the LLM from generating them.
Preprocessing
But you still need to pass recipient_email
to the tool execution so that handle_tool_calls
can successfully send the email.
Putting it all together
Postprocessing
After executing a tool call, the system sends the response back to the LLM. However many APIs tend to return lots of data in their responses, making agentic flows unstable and eating up tokens.
handle_tool_calls
by using execute_action
to directly call the GMAIL_FETCH_EMAILS tool.gpt-4o-mini
(128k tokens)!Postprocessing lets you filter what information from the tool execution reaches the LLM.
To filter only the subject and sender of the emails, create a postprocessor as follows:
The postprocessor produces a more digestible response for the LLMs.